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); } }
public void Add(string key, CacheLifetime lifeTime, object objectCache) { _memoryCache.Set(key, objectCache, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(DateTime.Now.AddMinutes(Convert.ToDouble(lifeTime)))); }
/// <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); }