Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Specified cast is not valid" Exception if expiration timeout is in the past #74

Closed
gplwhite opened this issue Jul 17, 2016 · 2 comments
Assignees
Milestone

Comments

@gplwhite
Copy link

Hello,

Due to a bug in the way I was calculating the expiration timespan to use when Putting items into a redis backed cache, I started receiving "Specified cast is not valid" exceptions when retrieving the item with the bad expiry time.

This seemed to be triggered if the expiry TimeSpan was a negative value (ie: in the past)

Maybe there should be some guarding against Adding/Putting already expired items, to avoid bad metadata making it into the cache?

Here's the stacktrace:

[InvalidCastException: Specified cast is not valid.]
   StackExchange.Redis.RedisValue.op_Explicit(RedisValue value) in RedisValue.cs:443
   CacheManager.Redis.<>c__DisplayClass35_0.<GetCacheItemInternal>b__0() +741
   CacheManager.Redis.RetryHelper.Retry(Func`1 retryme, Int32 timeOut, Int32 retries, ILogger logger) +226
   CacheManager.Redis.RedisCacheHandle`1.Retry(Func`1 retryme) +149
   CacheManager.Redis.RedisCacheHandle`1.GetCacheItemInternal(String key, String region) +347
   CacheManager.Redis.RedisCacheHandle`1.GetCacheItemInternal(String key) +46
   CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key) +65
   CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key, String region) +234
   CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key) +46
   CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key) +65

Thanks,
Greg

@MichaCo
Copy link
Owner

MichaCo commented Jul 27, 2016

I will have a look into it, your suggestion makes sense to me at least ;)

@MichaCo MichaCo added this to the Version 0.9.3 milestone Dec 3, 2016
@MichaCo MichaCo self-assigned this Dec 3, 2016
@MichaCo MichaCo closed this as completed in 55de58e Dec 3, 2016
@MichaCo
Copy link
Owner

MichaCo commented Dec 3, 2016

Sorry for the late action on this. But I added some more checks to prevent those kind of issues from happening, should be in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants