Пример #1
0
        private void SetEntry(CacheEntry entry)
        {
            if (this.disposed)
            {
                return;
            }

            DateTimeOffset utcNow   = this.clock.UtcNow;
            DateTimeOffset?nullable = new DateTimeOffset?();

            if (entry.absoluteExpirationRelativeToNow.HasValue)
            {
                DateTimeOffset dateTimeOffset          = utcNow;
                TimeSpan?      expirationRelativeToNow = entry.absoluteExpirationRelativeToNow;
                nullable = expirationRelativeToNow.HasValue ? dateTimeOffset + expirationRelativeToNow.GetValueOrDefault() : new DateTimeOffset?();
            }
            else if (entry.absoluteExpiration.HasValue)
            {
                nullable = entry.absoluteExpiration;
            }

            if (nullable.HasValue && (!entry.absoluteExpiration.HasValue || nullable.Value < entry.absoluteExpiration.Value))
            {
                entry.absoluteExpiration = nullable;
            }

            entry.LastAccessed = utcNow;
            if (this.entries.TryGetValue(entry.Key, out var cacheEntry))
            {
                cacheEntry.SetExpired(EvictionReason.Replaced);
            }

            if (!entry.CheckExpired(utcNow))
            {
                bool flag;
                if (cacheEntry == null)
                {
                    flag = this.entries.TryAdd(entry.Key, entry);
                }
                else
                {
                    flag = this.entries.TryUpdate(entry.Key, entry, cacheEntry);
                    if (!flag)
                    {
                        flag = this.entries.TryAdd(entry.Key, entry);
                    }
                }

                if (flag)
                {
                    entry.AttachTokens();
                }
                else
                {
                    entry.SetExpired((EvictionReason)2);
                    entry.InvokeEvictionCallbacks();
                }

                if (cacheEntry != null)
                {
                    cacheEntry.InvokeEvictionCallbacks();
                }
            }
            else
            {
                entry.InvokeEvictionCallbacks();
                if (cacheEntry != null)
                {
                    this.RemoveEntry(cacheEntry);
                }
            }

            this.StartScanForExpiredItems();
        }
Пример #2
0
 private void EntryExpired(CacheEntry entry)
 {
     this.RemoveEntry(entry);
     this.StartScanForExpiredItems();
 }