using System; using System.Collections.Generic; namespace VCommon.Caching { public class HashCacheManager { private readonly string _key; private readonly FixedCacheManager _underlying; public HashCacheManager(string server, int db, string key) { _key = key; _underlying = new FixedCacheManager(server, db); } public void Clean() => _underlying.KeyDelete(_key); public bool Exist(string field) => _underlying.HashFieldExist(_key, field); public bool Delete(string field) => _underlying.HashFieldDelete(_key, field); public long Delete(params string[] fields) => _underlying.HashFieldDelete(_key, fields); public CacheValue Fetch(string field, Func missingCacheValueProvider, CacheExpire expire = null) => _underlying.HashFieldFetch(_key, field, missingCacheValueProvider, expire); public T FetchJson(string field, Func missingCacheValueProvider, CacheExpire expire = null) => _underlying.HashFieldFetchJson(_key, field, missingCacheValueProvider, expire); public void SetJson(string field, T value, CacheExpire expire = null) => _underlying.HashFieldSetJson(_key, field, value, expire); public T GetJson(string field) => _underlying.HashFieldGetJson(_key, field); public void PurgeAndSet(IReadOnlyDictionary fields) => _underlying.HashFieldPurgeAndSet(_key, fields); public void DeleteByPattern(string pattern) => _underlying.HashFieldDeleteByPattern(_key, pattern); public IReadOnlyDictionary GetByPattern(string pattern) => _underlying.HashFieldGetByPattern(_key, pattern); public IReadOnlyDictionary GetByPatternJson(string pattern) => _underlying.HashFieldGetByPatternJson(_key, pattern); public void Set(string field, CacheValue value, CacheExpire expire = null) => _underlying.HashFieldSet(_key, field, value, expire); public CacheValue Get(string field) => _underlying.HashFieldGet(_key, field); public void Set(IReadOnlyDictionary field, CacheExpire expire = null) => _underlying.HashFieldSet(_key, field, expire); public long Increment(string field) => _underlying.HashFieldIncrement(_key, field); public long Decrement(string field) => _underlying.HashFieldDecrement(_key, field); public IReadOnlyDictionary Get(params string[] fields) => _underlying.HashFieldGet(_key, fields); public IReadOnlyDictionary FetchAsDic( IEnumerable fields, Func convertField, Func, IReadOnlyDictionary> missingCacheValueProvider, Func convertValueToCache, Func convertCacheToValue, CacheExpire expire = null) { return _underlying.HashFieldsFetchAsDic(_key, fields, convertField, missingCacheValueProvider, convertValueToCache, convertCacheToValue, expire); } } }