using System.Text.RegularExpressions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Cache;
///
/// Implements on top of a .
///
public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
{
private readonly IOptions _options;
private readonly IHostEnvironment? _hostEnvironment;
private readonly ISet _keys = new HashSet();
private static readonly TimeSpan _readLockTimeout = TimeSpan.FromSeconds(5);
private static readonly TimeSpan _writeLockTimeout = TimeSpan.FromSeconds(5);
private readonly ReaderWriterLockSlim _locker = new(LockRecursionPolicy.SupportsRecursion);
private bool _disposedValue;
///
/// Gets the internal memory cache, for tests only!
///
///
/// The memory cache.
///
internal MemoryCache MemoryCache { get; private set; }
///
/// Initializes a new instance of the .
///
public ObjectCacheAppCache()
: this(Options.Create(new MemoryCacheOptions()), NullLoggerFactory.Instance, null)
{ }
///
/// Initializes a new instance of the class.
///
/// The options.
/// The logger factory.
/// The host environment.
public ObjectCacheAppCache(IOptions options, ILoggerFactory loggerFactory, IHostEnvironment? hostEnvironment)
{
_options = options;
_hostEnvironment = hostEnvironment;
MemoryCache = new MemoryCache(_options, loggerFactory);
}
///
public object? Get(string key)
{
Lazy