public void WhenCreatingSlidingStaticPolicySlidingExpiryIsValid() { var policy = new StaticCachePolicy(TimeSpan.FromSeconds(1.5d)); var firstExpiryCheck = policy.GetExpiryDate(); var firstNowCheck = DateTimeOffset.Now; Assert.That(firstExpiryCheck.Subtract(firstNowCheck).TotalSeconds, Is.InRange(1.4d, 1.5d)); Assert.That(policy.IsExpired, Is.False); Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.That(policy.GetExpiryDate(), Is.EqualTo(firstExpiryCheck)); var debugNowCheck = DateTimeOffset.Now; var debugExpiryCheck = policy.GetExpiryDate(); Assert.That(debugExpiryCheck.Subtract(debugNowCheck).TotalSeconds, Is.InRange(0.4d, 0.5d)); Assert.That(policy.IsExpired, Is.False); Thread.Sleep(TimeSpan.FromSeconds(0.5d)); Assert.That(policy.IsExpired, Is.True); }
public CacheValueOf(T value) : this(value, StaticCachePolicy.CreateDefault()) { }
public Dictionary <String, HashSet <String> > GetSynonyms(int synonymBatchSize, RuntimeCacheAdapter cache, StaticCachePolicy staticCachePolicy) { var statisticLanguageTags = GetStatisticLanguageTags(); string synonymCacheKey = GetSynonymCacheKey(statisticLanguageTags); Dictionary <String, HashSet <String> > synonymsCached; if (TryGetCachedSynonym(synonymCacheKey, cache, out synonymsCached)) { return(synonymsCached); } var loadedSynonyms = LoadSynonymsFromSourceIndex(synonymBatchSize, statisticLanguageTags); var synonymDictionary = CreateSynonymDictionary(loadedSynonyms); cache.AddOrUpdate(synonymCacheKey, staticCachePolicy, synonymDictionary); return(synonymDictionary); }
public ICachePolicy GetPolicyFor(object cacheKey) { return(GetPolicyElementFor(cacheKey).IfNotNull(x => x.ToPolicy(), StaticCachePolicy.CreateDefault())); }