Beispiel #1
0
        public T Execute <T>(Func <T> method, CacheKeyItem cacheExecutionItem)
        {
            var result = GetFromCache(cacheExecutionItem.Key);

            if (result == null)
            {
                result = method();
                InsertInCache(cacheExecutionItem.Key, result, cacheExecutionItem.RefreshTime);
            }

            return((T)result);
        }
Beispiel #2
0
        public async Task <T> ExecuteAsync <T>(Func <Task <T> > method, CacheKeyItem cacheExecutionItem)
        {
            var result = GetFromCache(cacheExecutionItem.Key);

            if (result == null)
            {
                result = await method();

                InsertInCache(cacheExecutionItem.Key, result, cacheExecutionItem.RefreshTime);
            }

            return((T)result);
        }
Beispiel #3
0
        public static CacheKeyItem Format(this CacheKeyItem value, params string[] parameters)
        {
            var executionItem = new CacheKeyItem(value.Key, value.RefreshTime);

            if (parameters == null || parameters.Length == 0)
            {
                return(executionItem);
            }

            for (var i = 0; i < parameters.Length; i++)
            {
                executionItem.Key = executionItem.Key + "|" + (parameters[i] ?? "null");
            }

            return(executionItem);
        }