private T Set(CompositeCacheKey key, T cacheObject)
        {
            //randomize cache to imporve rehydration results (don't expire too many at the same time
            var minutes = Random.Next(45, 50);
            var span    = TimeSpan.FromMinutes(minutes);

            //soft expire the cache in half this time
            CacheExpiration[key] = DateTime.UtcNow.AddMinutes(minutes / 2d);
            return(_memCache.Set(key, cacheObject, span));
        }
        public T Get(CompositeCacheKey key)
        {
            // ReSharper disable once InconsistentlySynchronizedField
            if (_memCache.TryGetValue(key, out T returnValue))
            {
                return(returnValue);
            }

            lock (MyLock)
            {
                //double check in case of race to cache
                if (_memCache.TryGetValue(key, out returnValue))
                {
                    return(returnValue);
                }

                //otherwise lookup the data
                return(Set(key, Factory(key.SubKeys, new CancellationToken()).Result));
            }
        }
 public void ExpireCache(CompositeCacheKey key, DateTime expiration)
 {
     ExpireCache(new CacheExpiration {
         CacheKey = key, Expiration = expiration
     });
 }
 public void ExpireCache(CompositeCacheKey key)
 {
     ExpireCache(key, _dateTime.UtcNow);
 }