类 SohelpBootResourceCache

java.lang.Object
net.sohelp.boot.admin.core.cache.SohelpBootResourceCache
所有已实现的接口:
ISohelpCache

@Component public class SohelpBootResourceCache extends Object implements ISohelpCache
平台资源缓存(永不过期,按需失效)

存储策略:

  • Key "p:{filePath}" → 单条资源 JSON(用于按路径查询)
  • Key "l:{filePath}" → 指定前缀下的资源列表(用于 listByPath 查询)

NONE 模式每次直接查询 pb_sohelp_boot_file 表。

从以下版本开始:
2026/3/25
作者:
AaronFung
  • 构造器详细资料

    • SohelpBootResourceCache

      public SohelpBootResourceCache()
  • 方法详细资料

    • init

      @PostConstruct public void init()
      初始化缓存提供者

      在 Spring Bean 初始化完成后自动调用,通过 SohelpCacheManager 创建名为 "resource" 的缓存提供者,TTL 设置为 0 表示永不过期。

    • cacheName

      public String cacheName()
      获取缓存名称
      指定者:
      cacheName 在接口中 ISohelpCache
      返回:
      缓存唯一标识名称 "resource"
    • cacheDescription

      public String cacheDescription()
      获取缓存描述信息
      指定者:
      cacheDescription 在接口中 ISohelpCache
      返回:
      缓存的中文描述 "平台资源缓存"
    • getByPath

      @Comment("\u6839\u636e\u8def\u5f84\u83b7\u53d6\u8d44\u6e90") public com.alibaba.fastjson.JSONObject getByPath(String filePath)
      根据文件路径获取单条资源

      查找逻辑:

      1. 若路径为空,直接返回 null
      2. 若缓存未启用(NONE 模式),直接查询数据库。
      3. 若缓存已启用,先尝试从缓存中获取;未命中则查询数据库并写入缓存。
      参数:
      filePath - 资源文件路径
      返回:
      资源内容的 JSON 对象;未找到时返回 null
    • listByPath

      @Comment("\u6839\u636e\u8def\u5f84\u524d\u7f00\u83b7\u53d6\u8d44\u6e90\u5217\u8868") public List<com.alibaba.fastjson.JSONObject> listByPath(String filePath)
      根据路径前缀获取资源列表

      使用 SQL LIKE 前缀匹配查询指定路径下的所有资源。

      1. 若路径为空,返回空列表。
      2. 若缓存未启用(NONE 模式),直接查询数据库。
      3. 若缓存已启用,先尝试从缓存中获取列表;未命中则查询数据库并写入缓存。
      参数:
      filePath - 资源文件路径前缀
      返回:
      匹配的资源列表;未找到时返回空列表
    • exists

      @Comment("\u5224\u65ad\u8d44\u6e90\u662f\u5426\u5b58\u5728") public boolean exists(String filePath)
      判断指定路径的资源是否存在

      内部调用 getByPath(String) 进行判断。

      参数:
      filePath - 资源文件路径
      返回:
      资源存在返回 true;否则返回 false
    • reload

      @Comment("\u91cd\u8f7d\u6240\u6709\u8d44\u6e90\u7f13\u5b58") public void reload()
      重载所有资源缓存

      清空缓存中的全部数据,后续请求将重新从数据库加载。

      指定者:
      reload 在接口中 ISohelpCache
    • reload

      @Comment("\u91cd\u8f7d\u6307\u5b9a\u8def\u5f84\u7684\u8d44\u6e90\u7f13\u5b58") public void reload(String filePath)
      重载指定路径的资源缓存

      删除指定路径对应的单条缓存项,并同时失效可能包含该路径的列表缓存。

      参数:
      filePath - 需要重载缓存的资源文件路径
    • remove

      @Comment("\u6e05\u9664\u6307\u5b9a\u8def\u5f84\u7684\u8d44\u6e90\u7f13\u5b58") public void remove(String filePath)
      清除指定路径的资源缓存

      删除单条资源缓存项,并级联失效相关的列表缓存。

      指定者:
      remove 在接口中 ISohelpCache
      参数:
      filePath - 需要清除缓存的资源文件路径