ICacheManager.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using WingServerCommon.Interfaces.OpLog;
  2. namespace WingServerCommon.Interfaces.Cache
  3. {
  4. public interface ICacheManager
  5. {
  6. // <summary>
  7. /// Remove many cache record with specified document ids
  8. /// </summary>
  9. /// <param name="args">The db collection document uopdate or deletes args</param>
  10. void RemoveMany(CollectionDocumentChangedArgs args);
  11. }
  12. public interface IBaseCacheManager<T> : ICacheManager where T : ICacheObject
  13. {
  14. /// <summary>
  15. /// Register functions
  16. /// </summary>
  17. /// <param name="loadCacheFromDbWithId"></param>
  18. /// <param name="loadCachesFromDbWithIds"></param>
  19. void RegisterDBFunction(Func<string, T> loadCacheFromDbWithId, Func<IList<string>, IList<T>> loadCachesFromDbWithIds);
  20. /// <summary>
  21. /// Load cache from db objects
  22. /// </summary>
  23. /// <param name="cacheObjs">the cache object list</param>
  24. void LoadFromDbOject(IList<T> cacheObjs);
  25. /// <summary>
  26. /// Remove a cache record with specified document id
  27. /// </summary>
  28. /// <param name="documentId">The db collection document id</param>
  29. void Remove(string documentId);
  30. /// <summary>
  31. /// Add a cache object to cache manager
  32. /// </summary>
  33. /// <param name="cacheObj">A new cache object</param>
  34. void Add(T cacheObj);
  35. /// <summary>
  36. /// Get cache with specified document id
  37. /// </summary>
  38. /// <param name="documentId">the document id, the code in db</param>
  39. /// <typeparam name="T"></typeparam>
  40. /// <returns></returns>
  41. T Get(string documentId);
  42. /// <summary>
  43. /// Find values whith filters
  44. /// </summary>
  45. /// <param name="predicate"></param>
  46. /// <returns></returns>
  47. IList<T> Where(Func<T, bool> predicate);
  48. }
  49. public interface ICacheObject
  50. {
  51. /// <summary>
  52. /// The unique id for on record , the code in db actually
  53. /// </summary>
  54. /// <value></value>
  55. string Code { get; set; }
  56. }
  57. }