/// <summary> /// Wraps the existing <paramref name="store"/> in a <see cref="SimpleInmemoryCache"/> so that it can be consumed as /// and extended as an <see cref="ICache"/> instance /// </summary> /// <remarks> /// Use the <paramref name="options"/> to define such things as the <see cref="ICache.Id"/> and /// the extended behaviours that the cache instance should receive /// </remarks> public static ICache WrapCache(this ConcurrentDictionary <string, object> store, CacheCreationOptions options = null) { if (options != null) { var wrapped = new SimpleInmemoryCache(store, options.Id); return(new CacheDecoratorChainBuilder().AddDecorators(wrapped, options.DecoratorOptions)); } else { return(new SimpleInmemoryCache(store)); } }
/// <summary> /// Wraps the <paramref name="store"/> in a <see cref="ObjectCacheWrapper"/> so that it can be consumed and /// extended as an <see cref="ICache"/> instance /// </summary> /// <remarks> /// <para> /// Use the <paramref name="options"/> to define such things as the <see cref="ICache.Id"/> and /// the extended behaviours that the cache instance should receive /// </para> /// <para> /// Supply a <paramref name="cacheItemPolicySelector"/> that will return the <see cref="CacheItemPolicy"/> /// that should be associated with items added to the cache /// </para> /// </remarks> public static ICache WrapCache(this ObjectCache store, CacheCreationOptions options = null, Func <string, object, CacheItemPolicy> cacheItemPolicySelector = null) { if (options != null) { var wrapped = new ObjectCacheWrapper(store, options.InstanceName, cacheItemPolicySelector); return(new CacheDecoratorChainBuilder().AddDecorators(wrapped, options.DecoratorOptions)); } else { return(new ObjectCacheWrapper(store, cacheItemPolicySelector: cacheItemPolicySelector)); } }
public static ConcurrentDictionary <Type, Func <CacheIdentity, ICache> > CreateDefaultCacheCtors() { var ctors = new ConcurrentDictionary <Type, Func <CacheIdentity, ICache> >(); DoRegisterDefaultConstructor <ICache>(ctors, cacheId => new ConcurrentDictionary <string, object>() .WrapCache(CacheCreationOptions.DefaultsWith(cacheId))); DoRegisterDefaultConstructor <ObjectCache>(ctors, cacheId => new MemoryCache(cacheId.Name).WrapCache(CacheCreationOptions.DefaultsWith(cacheId))); DoRegisterDefaultConstructor <MemoryCache>(ctors, cacheId => new MemoryCache(cacheId.Name).WrapCache(CacheCreationOptions.DefaultsWith(cacheId))); return(ctors); }