public async ValueTask <NearCache> GetOrCreateNearCacheAsync(string name, NearCacheNamedOptions options, CancellationToken cancellationToken = default)
 {
     return(await _caches.GetOrAddAsync(name, async (n, token) =>
     {
         var nearCache = new NearCache(n, _cluster, _serializationService, _loggerFactory, options, GetMaxToleratedMissCount());
         await InitializeNearCache(nearCache).CAF();
         return nearCache;
     }, cancellationToken).CAF());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NearCacheNamedOptions"/> class.
 /// </summary>
 private NearCacheNamedOptions(NearCacheNamedOptions other)
 {
     EvictionPolicy       = other.EvictionPolicy;
     EvictionPercentage   = other.EvictionPercentage;
     InMemoryFormat       = other.InMemoryFormat;
     MaxIdleSeconds       = other.MaxIdleSeconds;
     CleanupPeriodSeconds = other.CleanupPeriodSeconds;
     MaxSize            = other.MaxSize;
     TimeToLiveSeconds  = other.TimeToLiveSeconds;
     InvalidateOnChange = other.InvalidateOnChange;
 }
        private long _lastExpire; // last time expiration ran

        /// <summary>
        /// Initializes a new instance of the <see cref="NearCacheBase"/> class.
        /// </summary>
        /// <param name="name">The name of the cache.</param>
        /// <param name="cluster">The cluster.</param>
        /// <param name="serializationService">The localization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        /// <param name="nearCacheNamedOptions">NearCache options.</param>
        protected NearCacheBase(string name, Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory, NearCacheNamedOptions nearCacheNamedOptions)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(ExceptionMessages.NullOrEmpty, nameof(name));
            }
            Name    = name;
            Cluster = cluster ?? throw new ArgumentNullException(nameof(cluster));
            SerializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService));
            LoggerFactory        = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            Options = nearCacheNamedOptions ?? throw new ArgumentNullException(nameof(nearCacheNamedOptions));

            _entries   = new ConcurrentAsyncDictionary <IData, NearCacheEntry>();
            Statistics = new NearCacheStatistics();

            _lastExpire = Clock.Never;

            _maxSize             = nearCacheNamedOptions.MaxSize;
            _maxIdleMilliseconds = nearCacheNamedOptions.MaxIdleSeconds * 1000;
            InMemoryFormat       = nearCacheNamedOptions.InMemoryFormat;
            _timeToLive          = nearCacheNamedOptions.TimeToLiveSeconds * 1000;
            _evictionPolicy      = nearCacheNamedOptions.EvictionPolicy;
            _evictionComparer    = GetEvictionComparer(_evictionPolicy);
            _evictionPercentage  = nearCacheNamedOptions.EvictionPercentage;
            _cleanupInterval     = nearCacheNamedOptions.CleanupPeriodSeconds * 1000;
        }
 public async ValueTask <NearCache <TValue> > GetOrCreateNearCacheAsync <TValue>(string name, NearCacheNamedOptions options, CancellationToken cancellationToken = default)
 => new NearCache <TValue>(await GetOrCreateNearCacheAsync(name, options, cancellationToken).CAF());
 /// <summary>
 /// Initializes a new instance of the <see cref="NearCache"/> class.
 /// </summary>
 /// <param name="name">The name of the cache.</param>
 /// <param name="cluster">The cluster.</param>
 /// <param name="serializationService">The localization service.</param>
 /// <param name="loggerFactory">A logger factory.</param>
 /// <param name="nearCacheNamedOptions">NearCache options.</param>
 /// <param name="maxToleratedMissCount"></param>
 public NearCache(string name, Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory, NearCacheNamedOptions nearCacheNamedOptions, int maxToleratedMissCount)
     : base(name, cluster, serializationService, loggerFactory, nearCacheNamedOptions)
 {
     _maxToleratedMissCount = maxToleratedMissCount;
 }