private CacheExpirySettings ReadExpirySection(IConfigurationSection expiry) { CacheExpiryType cacheExpiryType = CacheExpirySettings.Default.Type; TimeSpan ttl = CacheExpirySettings.Default.TTL; string typeConfigValue = expiry.GetSection("type").Value; if (typeConfigValue != null) { if (!Enum.TryParse(typeConfigValue, true, out cacheExpiryType)) { throw new InvalidOperationException($"Unable to read the 'type' property => '{expiry.Path}'"); } } string ttlConfigValue = expiry.GetSection("ttl").Value; if (ttlConfigValue != null) { if (!TimeSpan.TryParse(ttlConfigValue, out ttl)) { throw new InvalidOperationException($"Unable to read the 'ttl' property => '{expiry.Path}'"); } } return(new CacheExpirySettings(cacheExpiryType, ttl)); }
public CachingInfo(bool shouldCache, string cacheKey, TimeSpan timeToCache, CacheExpiryType expiryType) { ShouldCache = shouldCache; CacheKey = cacheKey; ExpiryType = expiryType; TimeToCache = shouldCache ? timeToCache : TimeSpan.Zero; }
public T Get <T>(string key, Func <T> func, TimeSpan time, CacheExpiryType cacheExpiryType) { key = InternalCachePrefix + key; object o = null; if (time > TimeSpan.Zero) { o = _cache[key]; } if (o != null) { return(o.To <T>()); } o = func.Invoke(); if (o != null) { if (time > TimeSpan.Zero) { var absoluteExpiration = cacheExpiryType == CacheExpiryType.Absolute ? DateTime.UtcNow.Add(time) : Cache.NoAbsoluteExpiration; var slidingExpiration = cacheExpiryType == CacheExpiryType.Sliding ? (time) : Cache.NoSlidingExpiration; _cache.Add(key, o, absoluteExpiration, slidingExpiration, CacheItemPriority.AboveNormal); } return(o.To <T>()); } return((T)(object)null); }
public CheckCommand(string key, CacheExpiryType expiryType, int expiryNumber) { CacheKeys = new CacheCommand<IList<string>>(key); ExpiryType = expiryType; ExpiryNumber = expiryNumber; }
public CacheExpirySettings(CacheExpiryType type, TimeSpan ttl) { Type = type; TTL = ttl; }
public WebpageOutputCacheableAttribute(CacheExpiryType expiryType, int length) { ExpiryType = expiryType; Length = length; }