using Umbraco.Cms.Core.Cache;
namespace Umbraco.Extensions;
///
/// Extensions for strongly typed access
///
public static class AppCacheExtensions
{
public static T? GetCacheItem(
this IAppPolicyCache provider,
string cacheKey,
Func getCacheItem,
TimeSpan? timeout,
bool isSliding = false,
string[]? dependentFiles = null)
{
var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles);
return result == null ? default : result.TryConvertTo().Result;
}
public static void InsertCacheItem(
this IAppPolicyCache provider,
string cacheKey,
Func getCacheItem,
TimeSpan? timeout = null,
bool isSliding = false,
string[]? dependentFiles = null) =>
provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles);
public static IEnumerable GetCacheItemsByKeySearch(this IAppCache provider, string keyStartsWith)
{
IEnumerable