Skip to content

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

@gplwhite

Description

@gplwhite

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions