Ejemplo n.º 1
0
        public ChunkCache(IAsyncCache <TKey, TChunk> cache)
        {
            Contracts.Requires.That(cache != null);

            this.cache      = cache;
            this.AsReadOnly = new ReadOnlyChunkCache(cache);
        }
Ejemplo n.º 2
0
 internal SessionAttribute(bool allowCookie, bool ignoreBadToken, IHttpClientProvider httpClientProvider, IAsyncCache cache)
 {
     _allowCookie        = allowCookie;
     _ignoreBadToken     = ignoreBadToken;
     _httpClientProvider = httpClientProvider;
     _cache = cache;
 }
Ejemplo n.º 3
0
 /// <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;
        }
Ejemplo n.º 5
0
 public MetadataService(ISqlItemTypeRepository sqlItemTypeRepository,
                        IMetadataRepository metadataRepository,
                        IImageService imageService,
                        IAsyncCache cache)
 {
     _sqlItemTypeRepository = sqlItemTypeRepository;
     _metadataRepository    = metadataRepository;
     _imageService          = imageService;
     _cache = cache;
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 11
0
 public Startup(IAsyncCache cache)
 {
     _cache = cache;
 }
Ejemplo n.º 12
0
 /// <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);
Ejemplo n.º 13
0
 /// <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);
Ejemplo n.º 14
0
 /// <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);
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 19
0
 /// <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;
 }
Ejemplo n.º 21
0
 /// <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);
Ejemplo n.º 22
0
 public TransfersController(IAccountService accountService, IAsyncCache cache)
 {
     this.accountService = accountService;
     this.cache          = cache;
 }
Ejemplo n.º 23
0
 protected ComputingCacheBase(IAsyncCache <TKey, TValue> cache, IAsyncLockSet <TKey>?lockSet = null)
 {
     Cache = cache;
     Locks = lockSet ?? new AsyncLockSet <TKey>(ReentryMode.CheckedFail);
 }
Ejemplo n.º 24
0
 public EventableAsyncCache(IAsyncCache targetCache)
 {
     this.targetCache = targetCache;
 }
Ejemplo n.º 25
0
 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;
 }