| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace Abp.Runtime.Caching
- {
- /// <summary>
- /// Defines a cache that can be store and get items by keys.
- /// </summary>
- public interface ICache : IDisposable
- {
- /// <summary>
- /// Unique name of the cache.
- /// </summary>
- string Name { get; }
- /// <summary>
- /// Default sliding expire time of cache items.
- /// Default value: 60 minutes (1 hour).
- /// Can be changed by configuration.
- /// </summary>
- TimeSpan DefaultSlidingExpireTime { get; set; }
- /// <summary>
- /// Default absolute expire time of cache items.
- /// Default value: null (not used).
- /// </summary>
- TimeSpan? DefaultAbsoluteExpireTime { get; set; }
- /// <summary>
- /// Gets an item from the cache.
- /// This method hides cache provider failures (and logs them),
- /// uses the factory method to get the object if cache provider fails.
- /// </summary>
- /// <param name="key">Key</param>
- /// <param name="factory">Factory method to create cache item if not exists</param>
- /// <returns>Cached item</returns>
- object Get(string key, Func<string, object> factory);
- /// <summary>
- /// Gets items from the cache.
- /// This method hides cache provider failures (and logs them),
- /// uses the factory method to get the object if cache provider fails.
- /// </summary>
- /// <param name="keys">Keys</param>
- /// <param name="factory">Factory method to create cache item if not exists</param>
- /// <returns>Cached item</returns>
- object[] Get(string[] keys, Func<string, object> factory);
- /// <summary>
- /// Gets an item from the cache.
- /// This method hides cache provider failures (and logs them),
- /// uses the factory method to get the object if cache provider fails.
- /// </summary>
- /// <param name="key">Key</param>
- /// <param name="factory">Factory method to create cache item if not exists</param>
- /// <returns>Cached item</returns>
- Task<object> GetAsync(string key, Func<string, Task<object>> factory);
- /// <summary>
- /// Gets items from the cache.
- /// This method hides cache provider failures (and logs them),
- /// uses the factory method to get the object if cache provider fails.
- /// </summary>
- /// <param name="keys">Keys</param>
- /// <param name="factory">Factory method to create cache item if not exists</param>
- /// <returns>Cached items</returns>
- Task<object[]> GetAsync(string[] keys, Func<string, Task<object>> factory);
- /// <summary>
- /// Gets an item from the cache or null if not found.
- /// </summary>
- /// <param name="key">Key</param>
- /// <returns>Cached item or null if not found</returns>
- object GetOrDefault(string key);
- /// <summary>
- /// Gets items from the cache. For every key that is not found, a null value is returned.
- /// </summary>
- /// <param name="keys">Keys</param>
- /// <returns>Cached items</returns>
- object[] GetOrDefault(string[] keys);
- /// <summary>
- /// Gets an item from the cache or null if not found.
- /// </summary>
- /// <param name="key">Key</param>
- /// <returns>Cached item or null if not found</returns>
- Task<object> GetOrDefaultAsync(string key);
- /// <summary>
- /// Gets items from the cache. For every key that is not found, a null value is returned.
- /// </summary>
- /// <param name="keys">Keys</param>
- /// <returns>Cached items</returns>
- Task<object[]> GetOrDefaultAsync(string[] keys);
- /// <summary>
- /// Saves/Overrides an item in the cache by a key.
- /// Use one of the expire times at most (<paramref name="slidingExpireTime"/> or <paramref name="absoluteExpireTime"/>).
- /// If none of them is specified, then
- /// <see cref="DefaultAbsoluteExpireTime"/> will be used if it's not null. Othewise, <see cref="DefaultSlidingExpireTime"/>
- /// will be used.
- /// </summary>
- /// <param name="key">Key</param>
- /// <param name="value">Value</param>
- /// <param name="slidingExpireTime">Sliding expire time</param>
- /// <param name="absoluteExpireTime">Absolute expire time</param>
- void Set(string key, object value, TimeSpan? slidingExpireTime = null, TimeSpan? absoluteExpireTime = null);
- /// <summary>
- /// Saves/Overrides items in the cache by the pairs.
- /// Use one of the expire times at most (<paramref name="slidingExpireTime"/> or <paramref name="absoluteExpireTime"/>).
- /// If none of them is specified, then
- /// <see cref="DefaultAbsoluteExpireTime"/> will be used if it's not null. Othewise, <see cref="DefaultSlidingExpireTime"/>
- /// will be used.
- /// </summary>
- /// <param name="pairs">Pairs</param>
- /// <param name="slidingExpireTime">Sliding expire time</param>
- /// <param name="absoluteExpireTime">Absolute expire time</param>
- void Set(KeyValuePair<string, object>[] pairs, TimeSpan? slidingExpireTime = null, TimeSpan? absoluteExpireTime = null);
- /// <summary>
- /// Saves/Overrides an item in the cache by a key.
- /// Use one of the expire times at most (<paramref name="slidingExpireTime"/> or <paramref name="absoluteExpireTime"/>).
- /// If none of them is specified, then
- /// <see cref="DefaultAbsoluteExpireTime"/> will be used if it's not null. Othewise, <see cref="DefaultSlidingExpireTime"/>
- /// will be used.
- /// </summary>
- /// <param name="key">Key</param>
- /// <param name="value">Value</param>
- /// <param name="slidingExpireTime">Sliding expire time</param>
- /// <param name="absoluteExpireTime">Absolute expire time</param>
- Task SetAsync(string key, object value, TimeSpan? slidingExpireTime = null, TimeSpan? absoluteExpireTime = null);
- /// <summary>
- /// Saves/Overrides items in the cache by the pairs.
- /// Use one of the expire times at most (<paramref name="slidingExpireTime"/> or <paramref name="absoluteExpireTime"/>).
- /// If none of them is specified, then
- /// <see cref="DefaultAbsoluteExpireTime"/> will be used if it's not null. Othewise, <see cref="DefaultSlidingExpireTime"/>
- /// will be used.
- /// </summary>
- /// <param name="pairs">Pairs</param>
- /// <param name="slidingExpireTime">Sliding expire time</param>
- /// <param name="absoluteExpireTime">Absolute expire time</param>
- Task SetAsync(KeyValuePair<string, object>[] pairs, TimeSpan? slidingExpireTime = null, TimeSpan? absoluteExpireTime = null);
- /// <summary>
- /// Removes a cache item by it's key (does nothing if given key does not exists in the cache).
- /// </summary>
- /// <param name="key">Key</param>
- void Remove(string key);
- /// <summary>
- /// Removes cache items by their keys.
- /// </summary>
- /// <param name="keys">Keys</param>
- void Remove(string[] keys);
- /// <summary>
- /// Removes a cache item by it's key (does nothing if given key does not exists in the cache).
- /// </summary>
- /// <param name="key">Key</param>
- Task RemoveAsync(string key);
- /// <summary>
- /// Removes cache items by their keys.
- /// </summary>
- /// <param name="keys">Keys</param>
- Task RemoveAsync(string[] keys);
- /// <summary>
- /// Clears all items in this cache.
- /// </summary>
- void Clear();
- /// <summary>
- /// Clears all items in this cache.
- /// </summary>
- Task ClearAsync();
- }
- }
|