Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public ActionResult <string> Get([FromRoute] string mykey)
 {
     return(_memory.Get(mykey)?.ToString());
 }
Exemplo n.º 3
0
        public void Get_NoDataInCache_ShouldReturn_Null()
        {
            var result = _inMemoryCache.Get <string>(Key);

            result.ShouldBeNull();
        }