public static async Task <Result <TResult> > GetCachedResult <TResult>(this IInMemoryCache memoryCache, string key, TimeSpan validFor, Func <Task <Result <TResult> > > value) where TResult : class { var cachedResult = memoryCache.Get <TResult>(key); if (cachedResult != null) { return(Success(cachedResult)); } var result = await value(); if (result.IsSuccess && result.Value != null) { memoryCache.Store(key, result.Value, validFor); } return(result); }
public ActionResult <string> Get([FromRoute] string mykey) { return(_memory.Get(mykey)?.ToString()); }
public void Get_NoDataInCache_ShouldReturn_Null() { var result = _inMemoryCache.Get <string>(Key); result.ShouldBeNull(); }