DataDictCacheService.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using YiSha.Business.Cache.IService;
  5. using YiSha.Cache.Factory;
  6. using YiSha.Entity.SystemManage;
  7. using YiSha.IService.SystemManage;
  8. using YiSha.Service.SystemManage;
  9. namespace YiSha.Business.Cache.Service
  10. {
  11. public class DataDictCacheService : IDataDictCacheService<DataDictEntity>
  12. {
  13. private IDataDictService _dataDictService;
  14. public DataDictCacheService(IDataDictService dataDictService)
  15. {
  16. _dataDictService = dataDictService;
  17. }
  18. public string CacheKey => this.GetType().Name;
  19. public async Task<List<DataDictEntity>> GetList()
  20. {
  21. var cacheList = CacheFactory.Cache.GetCache<List<DataDictEntity>>(CacheKey);
  22. if (cacheList == null)
  23. {
  24. var list = await _dataDictService.GetListPartial(null);
  25. CacheFactory.Cache.SetCache(CacheKey, list);
  26. return list;
  27. }
  28. else
  29. {
  30. return cacheList;
  31. }
  32. }
  33. public bool Remove()
  34. {
  35. return CacheFactory.Cache.RemoveCache(CacheKey);
  36. }
  37. }
  38. }