Interface CacheManager

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
EhcacheCacheManager

public interface CacheManager extends AutoCloseable

快取管理器介面

負責快取的生命週期管理,包含建立、取得、移除快取等操作。

Since:
1.0
  • Method Details

    • createCache

      <K,V> Cache<K,V> createCache(CacheConfiguration<K,V> configuration)
      建立快取
      Type Parameters:
      K - 鍵的型別
      V - 值的型別
      Parameters:
      configuration - 快取配置
      Returns:
      快取實例
      Throws:
      IllegalStateException - 若快取已存在
    • getCache

      <K,V> Cache<K,V> getCache(String name, Class<K> keyType, Class<V> valueType)
      取得快取
      Type Parameters:
      K - 鍵的型別
      V - 值的型別
      Parameters:
      name - 快取名稱
      keyType - 鍵的型別
      valueType - 值的型別
      Returns:
      快取實例,若不存在則返回 null
    • removeCache

      void removeCache(String name)
      移除快取
      Parameters:
      name - 快取名稱
    • getCacheNames

      Collection<String> getCacheNames()
      取得所有快取名稱
      Returns:
      快取名稱集合
    • hasCache

      boolean hasCache(String name)
      檢查快取是否存在
      Parameters:
      name - 快取名稱
      Returns:
      true 若快取存在
    • disableAll

      default void disableAll()

      停用此管理器下的所有快取(拉總閘)

      語意為邏輯旁路、不清空資料:停用期間所有 managed 快取的 getnull(強制 miss)、 put 被忽略;底層資料保留,enableAll() 後即可再服務。停用後新建立(含懶建)的 managed 快取也自動受此總閘管制。主要供除錯/測試「強制讀資料源」。

      預設實作拋 UnsupportedOperationException;具管理能力的實作(如內建 Ehcache)覆寫之。

    • enableAll

      default void enableAll()

      啟用此管理器下的所有快取(放總閘)

      僅翻回總閘,不會覆蓋個別快取以 disableCache(String) 設定的停用狀態。

      預設實作拋 UnsupportedOperationException;具管理能力的實作覆寫之。

    • isEnabled

      default boolean isEnabled()

      查詢管理器總閘是否為啟用

      預設實作回 true(不具管理能力的實作視為恆啟用)。

      Returns:
      true 若總閘為啟用
    • disableCache

      default void disableCache(String name)

      停用指定名稱的單一快取

      與總閘正交:即使總閘啟用,被指名的快取仍停用。可在快取建立之前先指名, 之後懶建的同名快取會以停用狀態誕生。

      預設實作拋 UnsupportedOperationException;具管理能力的實作覆寫之。

      Parameters:
      name - 快取名稱
    • enableCache

      default void enableCache(String name)

      啟用指定名稱的單一快取

      預設實作拋 UnsupportedOperationException;具管理能力的實作覆寫之。

      Parameters:
      name - 快取名稱
    • isCacheEnabled

      default boolean isCacheEnabled(String name)

      查詢指定快取的有效服務狀態(總閘 AND 個別開關)

      預設實作回 isEnabled()

      Parameters:
      name - 快取名稱
      Returns:
      true 若該快取目前會服務(總閘與個別開關皆啟用)
    • close

      void close()
      關閉管理器,釋放所有資源
      Specified by:
      close in interface AutoCloseable