BaseCache.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. declare(strict_types=1);
  15. namespace app\common\cache;
  16. use think\App;
  17. use think\Cache;
  18. /**
  19. * 缓存基础类,用于管理缓存
  20. * Class BaseCache
  21. * @package app\common\cache
  22. */
  23. abstract class BaseCache extends Cache
  24. {
  25. /**
  26. * 缓存标签
  27. * @var string
  28. */
  29. protected $tagName;
  30. public function __construct()
  31. {
  32. parent::__construct(app());
  33. $this->tagName = get_class($this);
  34. }
  35. /**
  36. * @notes 重写父类set,自动打上标签
  37. * @param string $key
  38. * @param mixed $value
  39. * @param null $ttl
  40. * @return bool
  41. * @author 段誉
  42. * @date 2021/12/27 14:16
  43. */
  44. public function set($key, $value, $ttl = null): bool
  45. {
  46. return $this->store()->tag($this->tagName)->set($key, $value, $ttl);
  47. }
  48. /**
  49. * @notes 清除缓存类所有缓存
  50. * @return bool
  51. * @author 段誉
  52. * @date 2021/12/27 14:16
  53. */
  54. public function deleteTag(): bool
  55. {
  56. return $this->tag($this->tagName)->clear();
  57. }
  58. }