public ChunkCache(IAsyncCache <TKey, TChunk> cache) { Contracts.Requires.That(cache != null); this.cache = cache; this.AsReadOnly = new ReadOnlyChunkCache(cache); }
internal SessionAttribute(bool allowCookie, bool ignoreBadToken, IHttpClientProvider httpClientProvider, IAsyncCache cache) { _allowCookie = allowCookie; _ignoreBadToken = ignoreBadToken; _httpClientProvider = httpClientProvider; _cache = cache; }
/// <summary> /// Adds a distributed cache to the resulting <see cref="IReadOnlyCache{TKey,TValue}"/> with a way to convert the /// <typeparamref name="TValue"/> to string and the <typeparamref name="TValue"/> to bytes. /// </summary> /// <param name="distributedCache">The distributed cache.</param> /// <param name="keyValueSerializer"><typeparamref name="TKey"/>/<typeparamref name="TValue"/> serializer.</param> /// <param name="keyPrefix">Prefix prepended to the distributed cache key.</param> /// <exception cref="ArgumentNullException"><paramref name="distributedCache"/> or <paramref name="keyValueSerializer"/> is null.</exception> /// <returns>A reference to this instance.</returns> public ReadOnlyCacheBuilder <TKey, TValue> WithDistributedCache(IAsyncCache distributedCache, IKeyValueSerializer <TKey, TValue> keyValueSerializer, string?keyPrefix = null) { _distributedCache = distributedCache ?? throw new ArgumentNullException(nameof(distributedCache)); _keyValueSerializer = keyValueSerializer ?? throw new ArgumentNullException(nameof(keyValueSerializer)); _keyPrefix = keyPrefix; return(this); }
public CacheDisposalWrapper(IAsyncCache <TKey, TValue> cache, IDisposable disposable) { Contracts.Requires.That(cache != null); Contracts.Requires.That(disposable != null); this.cache = cache; this.disposable = disposable; }
public MetadataService(ISqlItemTypeRepository sqlItemTypeRepository, IMetadataRepository metadataRepository, IImageService imageService, IAsyncCache cache) { _sqlItemTypeRepository = sqlItemTypeRepository; _metadataRepository = metadataRepository; _imageService = imageService; _cache = cache; }
public BoundedChunkCache( Predicate <TKey> isInBounds, IAsyncCache <TKey, TChunk> cache, IFactory <TKey, TChunk> outOfBounds) { Contracts.Requires.That(isInBounds != null); Contracts.Requires.That(cache != null); Contracts.Requires.That(outOfBounds != null); this.isInBounds = isInBounds; this.cache = cache; this.outOfBounds = outOfBounds; }
public AsyncCache( IAsyncFactory <TKey, ICacheValue <TKey, TValue> > factory, IEqualityComparer <TKey> comparer) { Contracts.Requires.That(factory != null); Contracts.Requires.That(comparer != null); this.cache = new AsyncCache <TKey, VoidStruct, TValue>( Factory.FromAsync((TKey key, VoidStruct unused) => factory.CreateAsync(key)), comparer); }
public OutputCacheAttribute( int timeoutMilliseconds = DefaultTimeoutMilliseconds, bool cacheOnClient = DefaultCacheOnClient, string contentType = DefaultContentType) { this.timeoutMilliseconds = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.TimeoutMilliseconds") ? int.Parse(ConfigurationManager.AppSettings["OutputCache.TimeoutMilliseconds"]) : timeoutMilliseconds; this.cacheOnClient = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.CacheOnClient") ? bool.Parse(ConfigurationManager.AppSettings["OutputCache.CacheOnClient"]) : cacheOnClient; this.contentType = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.ContentType") ? ConfigurationManager.AppSettings["OutputCache.ContentType"] : contentType; cache = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IAsyncCache)) as IAsyncCache; }
public FeaturesService(IFeaturesRepository featuresRepository, IFeatureLicenseHelper licenseHelper, IAsyncCache cache) { if (featuresRepository == null) { throw new ArgumentNullException(nameof(featuresRepository)); } _featuresRepository = featuresRepository; if (licenseHelper == null) { throw new ArgumentNullException(nameof(licenseHelper)); } _licenseHelper = licenseHelper; if (cache == null) { throw new ArgumentNullException(nameof(cache)); } _cache = cache; }
public OutputCacheAttribute( int timeoutMilliseconds = DefaultTimeoutMilliseconds, bool cacheOnClient = DefaultCacheOnClient, string contentType = DefaultContentType) { this.timeoutMilliseconds = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.TimeoutMilliseconds") ? int.Parse(ConfigurationManager.AppSettings["OutputCache.TimeoutMilliseconds"]) : timeoutMilliseconds; this.cacheOnClient = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.CacheOnClient") ? bool.Parse(ConfigurationManager.AppSettings["OutputCache.CacheOnClient"]) : cacheOnClient; this.contentType = ConfigurationManager.AppSettings.AllKeys.Contains("OutputCache.ContentType") ? ConfigurationManager.AppSettings["OutputCache.ContentType"] : contentType; cache = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof (IAsyncCache)) as IAsyncCache; }
public Startup(IAsyncCache cache) { _cache = cache; }
/// <summary> /// Determines whether this cache contains the specified key in the default partition. /// </summary> /// <param name="cache">The async cache.</param> /// <param name="key">The key.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>Whether this cache contains the specified key in the default partition.</returns> /// <remarks>Calling this method does not extend sliding items lifetime.</remarks> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> public static Task <bool> ContainsAsync(this IAsyncCache cache, string key, CancellationToken cancellationToken = default(CancellationToken)) => cache.ContainsAsync(cache.Settings.DefaultPartition, key, cancellationToken);
/// <summary> /// At first, it tries to get the cache item with default partition and specified key. If /// it is a "sliding" or "static" value, its lifetime will be increased by corresponding interval. /// /// If the value is not found, then it adds a "timed" value with given key and default /// partition. Value will last for the specified lifetime and, if accessed before expiry, /// its lifetime will _not_ be extended. /// </summary> /// <typeparam name="TVal">The type of the value.</typeparam> /// <param name="cache">The async cache.</param> /// <param name="key">The key.</param> /// <param name="valueGetter"> /// The function that is called in order to get the value when it was not found inside the cache. /// </param> /// <param name="lifetime">The desired lifetime.</param> /// <param name="parentKeys"> /// Keys, belonging to current partition, on which the new item will depend. /// </param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns> /// The value found in the cache or the one returned by <paramref name="valueGetter"/>, in /// case a new value has been added to the cache. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="key"/> or <paramref name="valueGetter"/> are null. /// </exception> /// <exception cref="NotSupportedException"> /// Too many parent keys have been specified for this item. Please have a look at the /// <see cref="IEssentialCache.MaxParentKeyCountPerItem"/> to understand how many parent /// keys each item may have. /// </exception> public static Task <TVal> GetOrAddTimedAsync <TVal>(this IAsyncCache cache, string key, Func <Task <TVal> > valueGetter, Duration lifetime, IList <string> parentKeys = null, CancellationToken cancellationToken = default(CancellationToken)) => cache.GetOrAddTimedAsync(cache.Settings.DefaultPartition, key, valueGetter, lifetime, parentKeys, cancellationToken);
/// <summary> /// Gets the item corresponding to default partition and given key, without updating expiry date. /// </summary> /// <param name="cache">The async cache.</param> /// <param name="key">The key.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <typeparam name="TVal">The type of the expected values.</typeparam> /// <returns> /// The item corresponding to default partition and givne key, without updating expiry date. /// </returns> /// <remarks> /// If you are uncertain of which type the value should have, you can always pass /// <see cref="object"/> as type parameter; that will work whether the required value is a /// class or not. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="NotSupportedException"> /// Cache does not support peeking (please have a look at the /// <see cref="IEssentialCache.CanPeek"/> property). /// </exception> public static Task <CacheResult <ICacheItem <TVal> > > PeekItemAsync <TVal>(this IAsyncCache cache, string key, CancellationToken cancellationToken = default(CancellationToken)) => cache.PeekItemAsync <TVal>(cache.Settings.DefaultPartition, key, cancellationToken);
public DefaultAuthenticator(IKernel kernel) { _users = kernel.Get <IUserManager>(); _asyncCache = kernel.Get <IAsyncCacheFactory>().Create(fetchUsersFunc, getUserKey); }
public static void GetPinAsync <TKey, TState, TValue>(IAsyncCache <TKey, TState, TValue> instance, TKey key) { Contracts.Requires.That(instance != null); Contracts.Requires.That(!instance.IsDisposed); Contracts.Requires.That(key != null); }
public CacheSharpSessionProvider(IAsyncCache cache) { this.cache = cache; }
public TransfersController(IAccountService accountService, IAsyncCache cache) { this.accountService = accountService; this.cache = cache; }
/// <summary> /// Removes the item with specified key from default partition. /// </summary> /// <param name="cache">The async cache.</param> /// <param name="key">The key.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> public static Task RemoveAsync(this IAsyncCache cache, string key, CancellationToken cancellationToken = default(CancellationToken)) => cache.RemoveAsync(cache.Settings.DefaultPartition, key, cancellationToken);
public CacheSharpSessionProvider(IAsyncCache cache) { this.cache = cache; }
/// <summary> /// Adds a "static" value with given key and default partition. Value will last as much as /// specified in <see cref="IEssentialCacheSettings.StaticInterval"/> and, if /// accessed before expiry, its lifetime will be extended by that interval. /// </summary> /// <typeparam name="TVal">The type of the value.</typeparam> /// <param name="cache">The async cache.</param> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="parentKeys"> /// Keys, belonging to current partition, on which the new item will depend. /// </param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> /// <exception cref="NotSupportedException"> /// Too many parent keys have been specified for this item. Please have a look at the /// <see cref="IEssentialCache.MaxParentKeyCountPerItem"/> to understand how many parent /// keys each item may have. /// </exception> public static Task AddStaticAsync <TVal>(this IAsyncCache cache, string key, TVal value, IList <string> parentKeys = null, CancellationToken cancellationToken = default(CancellationToken)) => cache.AddStaticAsync(cache.Settings.DefaultPartition, key, value, parentKeys, cancellationToken);
public TransfersController(IAccountService accountService, IAsyncCache cache) { this.accountService = accountService; this.cache = cache; }
protected ComputingCacheBase(IAsyncCache <TKey, TValue> cache, IAsyncLockSet <TKey>?lockSet = null) { Cache = cache; Locks = lockSet ?? new AsyncLockSet <TKey>(ReentryMode.CheckedFail); }
public EventableAsyncCache(IAsyncCache targetCache) { this.targetCache = targetCache; }
public ComputingCache(IAsyncCache <TKey, TValue> cache, Func <TKey, CancellationToken, ValueTask <TValue> > computer) : base(cache) => Computer = computer;
public InstrumentedAsyncCache(IAsyncCache cache, ICacheMetrics metrics, ILogger?logger) { _cache = cache; _metrics = metrics; _logger = logger; }