Esempio n. 1
0
        public async Task <T> GetOrSetAsync <T>(string key, Func <Task <T> > expression, TimeSpan expiresIn) where T : class
        {
            var found = Get <T>(key);

            if (found != null)
            {
                return(await TaskExtension.FromResultEx(found));
            }

            var executed = await expression();

            _cache.Set(key, executed, DateTime.Now + expiresIn);

            return(await TaskExtension.FromResultEx(executed));
        }