コード例 #1
0
        public async Task <T> Find <T>(string key, CacheLifetime lifeTime, Func <Task <T> > findFunction)
        {
            if (Contains(key))
            {
                return(Find <T>(key));
            }
            else
            {
                var result = findFunction();

                if (result != null)
                {
                    Add(key, lifeTime, result);
                }

                return(await result);
            }
        }
コード例 #2
0
 public void Add(string key, CacheLifetime lifeTime, object objectCache)
 {
     _memoryCache.Set(key, objectCache,
                      new MemoryCacheEntryOptions()
                      .SetAbsoluteExpiration(DateTime.Now.AddMinutes(Convert.ToDouble(lifeTime))));
 }
コード例 #3
0
 /// <summary>
 /// Set the lifecycle of the cache<br/>
 /// 设置缓存的生命周期<br/>
 /// </summary>
 /// <param name="lifetime">Cache lifetime</param>
 /// <returns></returns>
 public CacheFactoryOptions WithLifetime(CacheLifetime lifetime)
 {
     Lifetime = lifetime;
     return(this);
 }