/// <summary>
 /// Initializes a new instance of the <see cref="NearCacheOptions"/> class.
 /// </summary>
 private NearCacheOptions(NearCacheOptions other)
 {
     ReconciliationIntervalSeconds    = other.ReconciliationIntervalSeconds;
     MinReconciliationIntervalSeconds = other.MinReconciliationIntervalSeconds;
     MaxToleratedMissCount            = other.ReconciliationIntervalSeconds;
     Configurations = new Dictionary <string, NearCacheNamedOptions>(other.Configurations.ToDictionary(
                                                                         x => x.Key,
                                                                         x => x.Value.Clone()));
 }
Beispiel #2
0
 public async ValueTask <NearCache> GetOrCreateNearCacheAsync(string name, NearCacheOptions 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).CfAwait();
         return nearCache;
     }, cancellationToken).CfAwait());
 }
        public NearCacheManager(Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory, NearCacheOptions options)
        {
            _cluster = cluster;
            _serializationService = serializationService;
            _loggerFactory        = loggerFactory;
            _logger  = loggerFactory.CreateLogger <NearCacheManager>();
            _options = options;

            _reconciliationIntervalMillis = GetReconciliationIntervalSeconds() * 1000;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NearCacheOptions"/> class.
 /// </summary>
 private NearCacheOptions(NearCacheOptions 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="nearCacheOptions">NearCache options.</param>
        protected NearCacheBase(string name, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory, NearCacheOptions nearCacheOptions)
        {
            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 = nearCacheOptions ?? throw new ArgumentNullException(nameof(nearCacheOptions));

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

            _lastExpire = Clock.Never;

            _maxSize             = nearCacheOptions.MaxSize;
            _maxIdleMilliseconds = nearCacheOptions.MaxIdleSeconds * 1000;
            InMemoryFormat       = nearCacheOptions.InMemoryFormat;
            _timeToLive          = nearCacheOptions.TimeToLiveSeconds * 1000;
            _evictionPolicy      = nearCacheOptions.EvictionPolicy;
            _evictionComparer    = GetEvictionComparer(_evictionPolicy);
            _evictionPercentage  = nearCacheOptions.EvictionPercentage;
            _cleanupInterval     = nearCacheOptions.CleanupPeriodSeconds * 1000;
        }
Beispiel #6
0
 public async ValueTask <NearCache <TValue> > GetOrCreateNearCacheAsync <TValue>(string name, NearCacheOptions options, CancellationToken cancellationToken = default)
 => new NearCache <TValue>(await GetOrCreateNearCacheAsync(name, options, cancellationToken).CfAwait());
 /// <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="nearCacheOptions">NearCache options.</param>
 /// <param name="maxToleratedMissCount"></param>
 public NearCache(string name, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory, NearCacheOptions nearCacheOptions, int maxToleratedMissCount)
     : base(name, cluster, serializationService, loggerFactory, nearCacheOptions)
 {
     _maxToleratedMissCount = maxToleratedMissCount;
 }