/// <summary> /// Sets a IDropOutToken to object for a way to for drop out from cache that object which attached with this token . /// </summary> /// <param name="entry"></param> /// <param name="DropOutToken object"></param> public static ICacheEntry IDropOutToken( this ICacheEntry entry, IDropOutToken dropOutToken) { entry.DropOutToken = dropOutToken; return(entry); }
internal CacheEntry( object key, Action <CacheEntry> notifyCacheEntryDisposed, Action <CacheEntry> notifyCacheOfExpiration, IDropOutToken dropOutToken = null) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (notifyCacheEntryDisposed == null) { throw new ArgumentNullException(nameof(notifyCacheEntryDisposed)); } if (notifyCacheOfExpiration == null) { throw new ArgumentNullException(nameof(notifyCacheOfExpiration)); } Key = key; DropOutToken = dropOutToken; _notifyCacheEntryDisposed = notifyCacheEntryDisposed; _notifyCacheOfExpiration = notifyCacheOfExpiration; _scope = CacheEntryHelper.EnterScope(this); }
/// <inheritdoc /> public ICacheEntry CreateEntry(object key, IDropOutToken dropOutToken = null) { CheckDisposed(); return(new CacheEntry( key, _setEntry, _entryExpirationNotification )); }
public static TItem Set <TItem>(this IMemoryCache cache, object key, TItem value, MemoryCacheEntryOptions options, IDropOutToken dropOutToken = null) { using (var entry = cache.CreateEntry(key)) { if (options != null) { entry.SetOptions(options); } entry.Value = value; entry.DropOutToken = dropOutToken; } return(value); }
public static TItem Set <TItem>(this IMemoryCache cache, object key, TItem value, IChangeToken expirationToken, IDropOutToken dropOutToken = null) { var entry = cache.CreateEntry(key); entry.AddExpirationToken(expirationToken); entry.Value = value; entry.DropOutToken = dropOutToken; entry.Dispose(); return(value); }
public static TItem Set <TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow, IDropOutToken dropOutToken = null) { var entry = cache.CreateEntry(key); entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow; entry.Value = value; entry.DropOutToken = dropOutToken; entry.Dispose(); return(value); }
public static TItem Set <TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration, IDropOutToken dropOutToken = null) { var entry = cache.CreateEntry(key); entry.AbsoluteExpiration = absoluteExpiration; entry.Value = value; entry.DropOutToken = dropOutToken; entry.Dispose(); return(value); }
public static async Task <TItem> GetOrCreateAsync <TItem>(this IMemoryCache cache, object key, Func <ICacheEntry, Task <TItem> > factory, IDropOutToken dropOutToken = null) { object result; if (!cache.TryGetValue(key, out result)) { var entry = cache.CreateEntry(key); entry.DropOutToken = dropOutToken; result = await factory(entry); entry.SetValue(result); // need to manually call dispose instead of having a using // in case the factory passed in throws, in which case we // do not want to add the entry to the cache entry.Dispose(); } return((TItem)result); }