using System; using System.Collections.Generic; using System.Linq; namespace Umbraco.Core.Cache { /// /// Extensions for strongly typed access /// internal static class CacheProviderExtensions { //T GetCacheItem(string cacheKey, TimeSpan? timeout, Func getCacheItem); //T GetCacheItem(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func getCacheItem); //T GetCacheItem(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func getCacheItem); //T GetCacheItem(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan? timeout, Func getCacheItem); public static void ClearCacheObjectTypes(this ICacheProvider provider) { provider.ClearCacheObjectTypes(typeof(T).ToString()); } public static IEnumerable GetCacheItemsByKeySearch(this ICacheProvider provider, string keyStartsWith) { var result = provider.GetCacheItemsByKeySearch(keyStartsWith); return result.Select(x => ObjectExtensions.TryConvertTo(x).Result); } public static T GetCacheItem(this ICacheProvider provider, string cacheKey) { var result = provider.GetCacheItem(cacheKey); if (result == null) { return default(T); } return result.TryConvertTo().Result; } public static T GetCacheItem(this ICacheProvider provider, string cacheKey, Func getCacheItem) { var result = provider.GetCacheItem(cacheKey, () => getCacheItem()); if (result == null) { return default(T); } return result.TryConvertTo().Result; } } }