/// <inheritdoc /> /// <summary> /// Sets an item into cache /// </summary> /// <typeparam name="T">The type of item</typeparam> /// <param name="key">Name of the item in cache</param> /// <param name="item">The item being set into cache</param> public virtual void Set <T>(string key, T item) { var expiration = DateTimeOffset.Now.AddSeconds(Options.Seconds); // Optionally place in L1 Cache if (Options.UseLocalCache) { var l1Options = new MemoryCacheEntryOptions { AbsoluteExpiration = expiration, Priority = Options.Priority }; L1Cache.Set(key, item, l1Options); } // Optionally place in L2 Cache if (Options.UseDistributedCache) { // If these calls fail, do nothing try { var obj = new L2CacheItem <T>(Options.Seconds, Options.Priority, item); var l2Options = new DistributedCacheEntryOptions { AbsoluteExpiration = expiration }; L2Cache.Set(key, obj.ToByteArray(), l2Options); } catch { } } }
/// <inheritdoc /> /// <summary> /// Sets an item into cache /// </summary> /// <typeparam name="T">The type of item</typeparam> /// <param name="key">Name of the item in cache</param> /// <param name="item">The item being set into cache</param> public virtual void Set <T>(string key, T item) { var expiration = DateTimeOffset.Now.AddSeconds(Options.Seconds); // If these calls fail, do nothing try { var obj = new L2CacheItem <T>(Options.Seconds, Options.Priority, item); var l2Options = new DistributedCacheEntryOptions { AbsoluteExpiration = expiration }; L2Cache.Set(key, obj.ToByteArray(), l2Options); } catch { } }