Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheContainerBase{TKey, TEntity}"/> class.
        /// </summary>
        /// <param name="containerOptions">The container options.</param>
        /// <param name="retrievalOptions">The retrieval options.</param>
        public CacheContainerBase(CacheContainerOptions containerOptions, CacheAutoRetrievalOptions <TKey, TEntity> retrievalOptions = null)
        {
            containerOptions.CheckNullObject(nameof(containerOptions));

            ContainerOptions      = containerOptions ?? new CacheContainerOptions();
            ContainerOptions.Name = ContainerOptions.Name.SafeToString(typeof(TEntity).GetFullName());

            var expirationInSecond = containerOptions.ExpirationInSecond;

            AutoRetrievalOptions = retrievalOptions ?? new CacheAutoRetrievalOptions <TKey, TEntity>(null, BaseCacheAutoRetrievalOptions.Default);

            CacheRealm.RegisterCacheContainer(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheContainer{TKey, TEntity}" /> class.
        /// </summary>
        /// <param name="containerOptions">The container options.</param>
        /// <param name="keyGenerator">The key generator.</param>
        /// <param name="retrievalOptions">The retrieval options.</param>
        public RedisCacheContainer(RedisCacheOptions containerOptions = null, IRedisKeyGenerator <TKey> keyGenerator = null, CacheAutoRetrievalOptions <TKey, TEntity> retrievalOptions = null) : base(containerOptions, retrievalOptions)
        {
            if (containerOptions == null)
            {
                containerOptions = new RedisCacheOptions();
            }

            EntityName   = containerOptions.UseEntityFullName ? typeof(TEntity).ToCodeLook() : typeof(TEntity).Name;
            KeyGenerator = keyGenerator ?? new DefaultRedisKeyGenerator <TKey>(EntityName);
            Client       = GetMultiplexer(containerOptions.Endpoints, (containerOptions.DatabaseIndex));
        }
Ejemplo n.º 3
0
 public CacheContainerBase(string name, long?expirationInSecond = null, CacheAutoRetrievalOptions <TKey, TEntity> retrievalOptions = null)
     : this(new CacheContainerOptions {
     Name = name, ExpirationInSecond = expirationInSecond
 }, retrievalOptions)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryCacheContainer{TKey, TEntity}"/> class.
        /// </summary>
        /// <param name="containerOptions">The container options.</param>
        /// <param name="retrievalOptions">The retrieval options.</param>
        public MemoryCacheContainer(MemoryCacheContainerOptions <TKey> containerOptions, CacheAutoRetrievalOptions <TKey, TEntity> retrievalOptions = null)
            : base(containerOptions, retrievalOptions)
        {
            var capacity = containerOptions?.Capacity;

            Capacity = (capacity.HasValue && capacity.Value > 1) ? capacity : null;
            var equalityComparer = containerOptions?.EqualityComparer ?? EqualityComparer <TKey> .Default;

            container = capacity == null ? new SequencedKeyDictionary <TKey, MemoryCacheItem <TEntity> >(equalityComparer) : new SequencedKeyDictionary <TKey, MemoryCacheItem <TEntity> >(capacity.Value, equalityComparer);
            Statistic = new MemoryCacheStatistic();
        }