Esempio n. 1
0
        /// <summary>
        /// Registers a new cache.
        /// </summary>
        /// <param name="name">The cache's name.</param>
        /// <param name="options">The cache entry options.</param>
        /// <returns>the cache factory with specified cache registration.</returns>
        /// <exception cref="ArgumentNullException">The argument <paramref name="name"/> is null.</exception>
        /// <exception cref="ArgumentException">The argument <paramref name="name"/> is a white space string..</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="options"/> is null.</exception>
        /// <remarks>If a duplicate cache is registered, it will be overridden.</remarks>
        public ICacheFactory Register(string name, CacheEntryOptions options)
        {
            Guard.ArgumentNotNullOrWhiteSpace(name, nameof(name));
            Guard.ArgumentNotNull(options, nameof(options));

            _optionsMap[name] = options;
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="Cache"/>.
        /// </summary>
        /// <param name="name">The name of the cache to create.</param>
        /// <exception cref="ArgumentNullException">The argument <paramref name="name"/> is null.</exception>
        /// <exception cref="ArgumentException">The argument <paramref name="name"/> is a white space string.</exception>
        public Cache(string name)
        {
            Guard.ArgumentNotNullOrWhiteSpace(name, nameof(name));

            this.Name             = name;
            _options4KeysAndTypes = new CacheEntryOptions
            {
                Priority          = CacheItemPriority.NeverRemove,
                SlidingExpiration = TimeSpan.MaxValue
            };
            _waitHandle   = new EventWaitHandle(true, EventResetMode.AutoReset);
            _keyGenerator = new KeyGenerator(this);
        }
Esempio n. 3
0
 /// <summary>
 /// Create a new cache.
 /// </summary>
 /// <param name="name">The cache's name.</param>
 /// <param name="options">The cache entry options.</param>
 /// <returns>The cache to create.</returns>
 internal protected abstract ICache Create(string name, CacheEntryOptions options);
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 internal protected abstract Task SetCoreAsync(string key, object value, CacheEntryOptions options = null);