MenuCacheService.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace YiSha.Business.Cache.Service
  9. {
  10. public class MenuCacheService : IMenuCacheService<MenuEntity>
  11. {
  12. private IMenuService _menuService;
  13. public MenuCacheService(IMenuService menuService)
  14. {
  15. _menuService = menuService;
  16. }
  17. public string CacheKey => this.GetType().Name;
  18. public async Task<List<MenuEntity>> GetList()
  19. {
  20. var cacheList = CacheFactory.Cache.GetCache<List<MenuEntity>>(CacheKey);
  21. if (cacheList == null)
  22. {
  23. var list = await _menuService.GetListPartial(null);
  24. CacheFactory.Cache.SetCache(CacheKey, list);
  25. return list;
  26. }
  27. else
  28. {
  29. return cacheList;
  30. }
  31. }
  32. public bool Remove()
  33. {
  34. return CacheFactory.Cache.RemoveCache(CacheKey);
  35. }
  36. }
  37. }