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