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); }
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); }
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); }