FixedCacheManager.cs 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. namespace VCommon.Caching
  4. {
  5. public class FixedCacheManager
  6. {
  7. private readonly int _fixedDb;
  8. private readonly CacheManager _underlying;
  9. public FixedCacheManager(string server, int fixedDb)
  10. {
  11. _fixedDb = fixedDb;
  12. _underlying = new CacheManager(server);
  13. }
  14. public void KeyExpire(string key, CacheExpire expire) => _underlying.KeyExpire(_fixedDb, key, expire);
  15. public bool KeyExist(string key) => _underlying.KeyExist(_fixedDb, key);
  16. public bool KeyDelete(string key) => _underlying.KeyDelete(_fixedDb, key);
  17. public void KeySetJson(string key, object value, CacheExpire expire = null) => _underlying.KeySetJson(_fixedDb, key, value, expire);
  18. public T KeyGetJson<T>(string key) => _underlying.KeyGetJson<T>(_fixedDb, key);
  19. public T KeyGetFetchJson<T>(string key, Func<T> missProvider, CacheExpire expire = null) => _underlying.KeyFetchJson<T>(_fixedDb, key, missProvider, expire);
  20. public CacheValue KeyGetFetch(string key, Func<CacheValue> missProvider, CacheExpire expire = null) => _underlying.KeyFetch(_fixedDb, key, missProvider, expire);
  21. public void KeySet(string key, CacheValue value, CacheExpire expire = null) => _underlying.KeySet(_fixedDb, key, value, expire);
  22. public CacheValue KeyGet(string key) => _underlying.KeyGet(_fixedDb, key);
  23. public bool HashFieldExist(string hashKey, string hashField) => _underlying.HashFieldExist(_fixedDb, hashKey, hashField);
  24. public bool HashFieldDelete(string hashKey, string hashField) => _underlying.HashFieldDelete(_fixedDb, hashKey, hashField);
  25. public long HashFieldDelete(string hashKey, params string[] hashFields) => _underlying.HashFieldDelete(_fixedDb, hashKey, hashFields);
  26. public CacheValue HashFieldFetch(string hashKey, string hashField, Func<CacheValue> missingCacheValueProvider, CacheExpire expire = null) => _underlying.HashFieldFetch(_fixedDb, hashKey, hashField, missingCacheValueProvider, expire);
  27. public T HashFieldFetchJson<T>(string hashKey, string hashField, Func<T> missingCacheValueProvider, CacheExpire expire = null) => _underlying.HashFieldFetchJson(_fixedDb, hashKey, hashField, missingCacheValueProvider, expire);
  28. public void HashFieldSetJson<T>(string hashKey, string hashField, T value, CacheExpire expire = null) => _underlying.HashFieldSetJson(_fixedDb, hashKey, hashField, value, expire);
  29. public void HashFieldSetJson<T>(string hashKey, IReadOnlyDictionary<string, T> entries, CacheExpire expire = null) => _underlying.HashFieldSetJson(_fixedDb, hashKey, entries, expire);
  30. public T HashFieldGetJson<T>(string hashKey, string hashField) => _underlying.HashFieldGetJson<T>(_fixedDb, hashKey, hashField);
  31. public void HashFieldPurgeAndSet(string hashKey, IReadOnlyDictionary<string, CacheValue> hashFields) => _underlying.HashFieldPurgeAndSet(_fixedDb, hashKey, hashFields);
  32. public void HashFieldDeleteByPattern(string hashKey, string pattern) => _underlying.HashFieldDeleteByPattern(_fixedDb, hashKey, pattern);
  33. public IReadOnlyDictionary<string, CacheValue> HashFieldGetByPattern(string hashKey, string pattern) => _underlying.HashFieldGetByPattern(_fixedDb, hashKey, pattern);
  34. public IReadOnlyDictionary<string, T> HashFieldGetByPatternJson<T>(string hashKey, string pattern) => _underlying.HashFieldGetByPatternJson<T>(_fixedDb, hashKey, pattern);
  35. public void HashFieldSet(string hashKey, string hashField, CacheValue value, CacheExpire expire = null) => _underlying.HashFieldSet(_fixedDb, hashKey, hashField, value, expire);
  36. public CacheValue HashFieldGet(string hashKey, string hashField) => _underlying.HashFieldGet(_fixedDb, hashKey, hashField);
  37. public void HashFieldSet(string hashKey, IReadOnlyDictionary<string, CacheValue> hashField, CacheExpire expire = null) => _underlying.HashFieldSet(_fixedDb, hashKey, hashField, expire);
  38. public long HashFieldIncrement(string hashKey, string hashField) => _underlying.HashFieldIncrement(_fixedDb, hashKey, hashField);
  39. public long HashFieldDecrement(string hashKey, string hashField) => _underlying.HashFieldDecrement(_fixedDb, hashKey, hashField);
  40. public IReadOnlyDictionary<string, CacheValue> HashFieldGet(string hashKey, params string[] hashFields) => _underlying.HashFieldGet(_fixedDb, hashKey, hashFields);
  41. public IReadOnlyDictionary<TK, TV> HashFieldsFetchAsDic<TK, TV>(string key, IEnumerable<TK> hashFields,
  42. Func<TK, string> convertHashField,
  43. Func<IEnumerable<TK>, IReadOnlyDictionary<TK, TV>> missingCacheValueProvider,
  44. Func<TV, CacheValue> convertValueToCache,
  45. Func<CacheValue, TV> convertCacheToValue,
  46. CacheExpire expire = null) => _underlying.HashFieldsFetchAsDic(_fixedDb, key, hashFields, convertHashField, missingCacheValueProvider, convertValueToCache, convertCacheToValue, expire);
  47. public string[] SearchKeys(string pattern) => _underlying.SearchKeys(_fixedDb, pattern);
  48. }
  49. }