Interface CacheService

All Known Implementing Classes:
CacheServiceImpl

public interface CacheService
Since:
2025-01-03
Author:
Catch
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    cache(String key, Supplier<T> supplier, Class<?> wrapper, Class<?>... inners)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存 此方法支持嵌套类型的缓存, 如 List<User>
    <T> T
    cache(String key, Supplier<T> supplier, Class<T> target)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存
    <T> T
    cache(String key, Supplier<T> supplier, Duration timeout, Class<?> wrapper, Class<?>... inners)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存 此方法支持嵌套类型的缓存, 如 List<User>
    <T> T
    cache(String key, Supplier<T> supplier, Duration timeout, Class<T> target)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存
    void
    从缓存中移除指定 key 的值
    void
    从缓存中移除指定多个 key 的值
    void
    evictAll(String pattern)
    从缓存中移除所有匹配指定模式的 key 的值
    <T> T
    keep(String key, Supplier<T> supplier, Class<?> wrapper, Class<?>... inners)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存, 此方法中 key 用不过期 此方法支持嵌套类型的缓存, 如 List<User>
    <T> T
    keep(String key, Supplier<T> supplier, Class<T> target)
    缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存, 此方法中 key 用不过期
  • Method Details

    • cache

      <T> T cache(String key, Supplier<T> supplier, Class<T> target)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      target - 缓存值的类型
      Returns:
      缓存的值
    • cache

      <T> T cache(String key, Supplier<T> supplier, Duration timeout, Class<T> target)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      timeout - 缓存值的过期时间, 为 null 则使用默认过期时间
      target - 缓存值的类型
      Returns:
      缓存的值
    • cache

      <T> T cache(String key, Supplier<T> supplier, Class<?> wrapper, Class<?>... inners)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存 此方法支持嵌套类型的缓存, 如 List<User>
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      wrapper - 缓存值的包装类
      inners - 缓存值的内部类
      Returns:
      缓存的值
    • cache

      <T> T cache(String key, Supplier<T> supplier, Duration timeout, Class<?> wrapper, Class<?>... inners)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存 此方法支持嵌套类型的缓存, 如 List<User>
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      timeout - 缓存值的过期时间, 为 null 则使用默认过期时间
      wrapper - 缓存值的包装类
      inners - 缓存值的内部类
      Returns:
      缓存的值
    • keep

      <T> T keep(String key, Supplier<T> supplier, Class<T> target)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存, 此方法中 key 用不过期
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      target - 缓存值的类型
      Returns:
      缓存的值
    • keep

      <T> T keep(String key, Supplier<T> supplier, Class<?> wrapper, Class<?>... inners)
      缓存指定 key 的值,如果缓存中不存在,则使用 supplier 函数获取并缓存, 此方法中 key 用不过期 此方法支持嵌套类型的缓存, 如 List<User>
      Parameters:
      key - 缓存键
      supplier - 缓存值的提供者
      wrapper - 缓存值的包装类
      inners - 缓存值的内部类
      Returns:
      缓存的值
    • evict

      void evict(String key)
      从缓存中移除指定 key 的值
      Parameters:
      key - 缓存键
    • evict

      void evict(Collection<String> keys)
      从缓存中移除指定多个 key 的值
      Parameters:
      keys - 缓存键集合
    • evictAll

      void evictAll(String pattern)
      从缓存中移除所有匹配指定模式的 key 的值

      匹配示例:

      h?llo matches hello, hallo and hxllo

      h*llo matches hllo and heeeello

      h[ae]llo matches hello and hallo, but not hillo

      h[^e]llo matches hallo, hbllo, ... but not hello

      h[a-b]llo matches hallo and hbllo

      Parameters:
      pattern - 匹配模式