Ejemplo n.º 1
0
 // Associates this entry with an update sentinel. If this entry has a sliding expiration, we need to
 // touch the sentinel so that it doesn't expire.
 internal void ConfigureUpdateSentinel(MemoryCacheStore sentinelStore, MemoryCacheEntry sentinelEntry)
 {
     lock (this) {
         if (_fields == null)
         {
             _fields = new SeldomUsedFields();
         }
         _fields._updateSentinel = Tuple.Create(sentinelStore, sentinelEntry);
     }
 }
Ejemplo n.º 2
0
        internal MemoryCacheEntry(string key,
                                  object value,
                                  DateTimeOffset absExp,
                                  TimeSpan slidingExp,
                                  CacheItemPriority priority,
                                  Collection <ChangeMonitor> dependencies,
                                  CacheEntryRemovedCallback removedCallback,
                                  MemoryCache cache) : base(key)
        {
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            _utcCreated = DateTime.UtcNow;
            _value      = value;

            _slidingExp = slidingExp;
            if (_slidingExp > TimeSpan.Zero)
            {
                _utcAbsExp = _utcCreated + _slidingExp;
            }
            else
            {
                _utcAbsExp = absExp.UtcDateTime;
            }

            _expiresEntryRef = ExpiresEntryRef.INVALID;
            _expiresBucket   = 0xff;

            _usageEntryRef = UsageEntryRef.INVALID;
            if (priority == CacheItemPriority.NotRemovable)
            {
                _usageBucket = 0xff;
            }
            else
            {
                _usageBucket = 0;
            }

            _callback = removedCallback;

            // CacheItemPolicy.ChangeMonitors is frequently the source for 'dependencies', and that property
            // is never null. So check that the collection of dependencies is not empty before allocating
            // the 'seldom' used fields.
            if (dependencies != null && dependencies.Count > 0)
            {
                _fields = new SeldomUsedFields();
                _fields._dependencies = dependencies;
                _fields._cache        = cache;
            }
        }
Ejemplo n.º 3
0
        internal MemoryCacheEntry(String key,
                                  Object value,
                                  DateTimeOffset absExp,
                                  TimeSpan slidingExp,
                                  CacheItemPriority priority,
                                  Collection <ChangeMonitor> dependencies,
                                  CacheEntryRemovedCallback removedCallback,
                                  MemoryCache cache) : base(key)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            _utcCreated = DateTime.UtcNow;
            _value      = value;

            _slidingExp = slidingExp;
            if (_slidingExp > TimeSpan.Zero)
            {
                _utcAbsExp = _utcCreated + _slidingExp;
            }
            else
            {
                _utcAbsExp = absExp.UtcDateTime;
            }

            _expiresEntryRef = ExpiresEntryRef.INVALID;
            _expiresBucket   = 0xff;

            _usageEntryRef = UsageEntryRef.INVALID;
            if (priority == CacheItemPriority.NotRemovable)
            {
                _usageBucket = 0xff;
            }
            else
            {
                _usageBucket = 0;
            }

            _callback = removedCallback;

            if (dependencies != null)
            {
                _fields = new SeldomUsedFields();
                _fields._dependencies = dependencies;
                _fields._cache        = cache;
            }
        }
Ejemplo n.º 4
0
        internal void UpdateSlidingExpForUpdateSentinel()
        {
            // We don't need a lock to get information about the update sentinel
            SeldomUsedFields fields = _fields;

            if (fields != null)
            {
                Tuple <MemoryCacheStore, MemoryCacheEntry> sentinelInfo = fields._updateSentinel;

                // touch the update sentinel to keep it from expiring
                if (sentinelInfo != null)
                {
                    MemoryCacheStore sentinelStore = sentinelInfo.Item1;
                    MemoryCacheEntry sentinelEntry = sentinelInfo.Item2;
                    sentinelStore.UpdateExpAndUsage(sentinelEntry, updatePerfCounters: false); // perf counters shouldn't be polluted by touching update sentinel entry
                }
            }
        }
Ejemplo n.º 5
0
 internal void AddDependent(MemoryCache cache, MemoryCacheEntryChangeMonitor dependent)
 {
     lock (this) {
         if (State > EntryState.AddedToCache)
         {
             return;
         }
         if (_fields == null)
         {
             _fields = new SeldomUsedFields();
         }
         if (_fields._cache == null)
         {
             _fields._cache = cache;
         }
         if (_fields._dependents == null)
         {
             _fields._dependents = new Dictionary <MemoryCacheEntryChangeMonitor, MemoryCacheEntryChangeMonitor>();
         }
         _fields._dependents[dependent] = dependent;
     }
 }
 internal void AddDependent(MemoryCache cache, MemoryCacheEntryChangeMonitor dependent)
 {
     lock (this)
     {
         if (this.State <= EntryState.AddedToCache)
         {
             if (this._fields == null)
             {
                 this._fields = new SeldomUsedFields();
             }
             if (this._fields._cache == null)
             {
                 this._fields._cache = cache;
             }
             if (this._fields._dependents == null)
             {
                 this._fields._dependents = new Dictionary<MemoryCacheEntryChangeMonitor, MemoryCacheEntryChangeMonitor>();
             }
             this._fields._dependents[dependent] = dependent;
         }
     }
 }
 internal MemoryCacheEntry(string key, object value, DateTimeOffset absExp, TimeSpan slidingExp, CacheItemPriority priority, Collection<ChangeMonitor> dependencies, CacheEntryRemovedCallback removedCallback, MemoryCache cache) : base(key)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     this._utcCreated = DateTime.UtcNow;
     this._value = value;
     this._slidingExp = slidingExp;
     if (this._slidingExp > TimeSpan.Zero)
     {
         this._utcAbsExp = this._utcCreated + this._slidingExp;
     }
     else
     {
         this._utcAbsExp = absExp.UtcDateTime;
     }
     this._expiresEntryRef = System.Runtime.Caching.ExpiresEntryRef.INVALID;
     this._expiresBucket = 0xff;
     this._usageEntryRef = System.Runtime.Caching.UsageEntryRef.INVALID;
     if (priority == CacheItemPriority.NotRemovable)
     {
         this._usageBucket = 0xff;
     }
     else
     {
         this._usageBucket = 0;
     }
     this._callback = removedCallback;
     if (dependencies != null)
     {
         this._fields = new SeldomUsedFields();
         this._fields._dependencies = dependencies;
         this._fields._cache = cache;
     }
 }
 // Associates this entry with an update sentinel. If this entry has a sliding expiration, we need to
 // touch the sentinel so that it doesn't expire.
 internal void ConfigureUpdateSentinel(MemoryCacheStore sentinelStore, MemoryCacheEntry sentinelEntry) {
     lock (this) {
         if (_fields == null) {
             _fields = new SeldomUsedFields();
         }
         _fields._updateSentinel = Tuple.Create(sentinelStore, sentinelEntry);
     }
 }