CacheController.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package beilv.web.controller.monitor;
  2. import org.apache.shiro.authz.annotation.RequiresPermissions;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.ModelMap;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.ResponseBody;
  10. import beilv.common.core.controller.BaseController;
  11. import beilv.common.core.domain.AjaxResult;
  12. import beilv.framework.web.service.CacheService;
  13. /**
  14. * 缓存监控
  15. *
  16. * @author ruoyi
  17. */
  18. @Controller
  19. @RequestMapping("/monitor/cache")
  20. public class CacheController extends BaseController
  21. {
  22. private String prefix = "monitor/cache";
  23. @Autowired
  24. private CacheService cacheService;
  25. @RequiresPermissions("monitor:cache:view")
  26. @GetMapping()
  27. public String cache(ModelMap mmap)
  28. {
  29. mmap.put("cacheNames", cacheService.getCacheNames());
  30. return prefix + "/cache";
  31. }
  32. @RequiresPermissions("monitor:cache:view")
  33. @PostMapping("/getNames")
  34. public String getCacheNames(String fragment, ModelMap mmap)
  35. {
  36. mmap.put("cacheNames", cacheService.getCacheNames());
  37. return prefix + "/cache::" + fragment;
  38. }
  39. @RequiresPermissions("monitor:cache:view")
  40. @PostMapping("/getKeys")
  41. public String getCacheKeys(String fragment, String cacheName, ModelMap mmap)
  42. {
  43. mmap.put("cacheName", cacheName);
  44. mmap.put("cacheKeys", cacheService.getCacheKeys(cacheName));
  45. return prefix + "/cache::" + fragment;
  46. }
  47. @RequiresPermissions("monitor:cache:view")
  48. @PostMapping("/getValue")
  49. public String getCacheValue(String fragment, String cacheName, String cacheKey, ModelMap mmap)
  50. {
  51. mmap.put("cacheName", cacheName);
  52. mmap.put("cacheKey", cacheKey);
  53. mmap.put("cacheValue", cacheService.getCacheValue(cacheName, cacheKey));
  54. return prefix + "/cache::" + fragment;
  55. }
  56. @RequiresPermissions("monitor:cache:view")
  57. @PostMapping("/clearCacheName")
  58. @ResponseBody
  59. public AjaxResult clearCacheName(String cacheName, ModelMap mmap)
  60. {
  61. cacheService.clearCacheName(cacheName);
  62. return AjaxResult.success();
  63. }
  64. @RequiresPermissions("monitor:cache:view")
  65. @PostMapping("/clearCacheKey")
  66. @ResponseBody
  67. public AjaxResult clearCacheKey(String cacheName, String cacheKey, ModelMap mmap)
  68. {
  69. cacheService.clearCacheKey(cacheName, cacheKey);
  70. return AjaxResult.success();
  71. }
  72. @RequiresPermissions("monitor:cache:view")
  73. @GetMapping("/clearAll")
  74. @ResponseBody
  75. public AjaxResult clearAll(ModelMap mmap)
  76. {
  77. cacheService.clearAll();
  78. return AjaxResult.success();
  79. }
  80. }