Class DisabledCacheManager

java.lang.Object
io.leandev.appfuse.cache.internal.DisabledCacheManager
All Implemented Interfaces:
CacheManager, AutoCloseable

public final class DisabledCacheManager extends Object implements CacheManager

Hard-disabled 的 No-Op CacheManager。

此類位於 internal 套件;公開入口為 CacheManagerBuilder.disabled()

  • Constructor Details

    • DisabledCacheManager

      public DisabledCacheManager()
  • Method Details

    • createCache

      public <K,V> Cache<K,V> createCache(CacheConfiguration<K,V> configuration)
      Description copied from interface: CacheManager
      建立快取
      Specified by:
      createCache in interface CacheManager
      Type Parameters:
      K - 鍵的型別
      V - 值的型別
      Parameters:
      configuration - 快取配置
      Returns:
      快取實例
    • getCache

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

      public void removeCache(String name)
      Description copied from interface: CacheManager
      移除快取
      Specified by:
      removeCache in interface CacheManager
      Parameters:
      name - 快取名稱
    • getCacheNames

      public Collection<String> getCacheNames()
      Description copied from interface: CacheManager
      取得所有快取名稱
      Specified by:
      getCacheNames in interface CacheManager
      Returns:
      快取名稱集合
    • hasCache

      public boolean hasCache(String name)
      Description copied from interface: CacheManager
      檢查快取是否存在
      Specified by:
      hasCache in interface CacheManager
      Parameters:
      name - 快取名稱
      Returns:
      true 若快取存在
    • disableAll

      public void disableAll()
      Description copied from interface: CacheManager

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

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

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

      Specified by:
      disableAll in interface CacheManager
    • enableAll

      public void enableAll()
      Description copied from interface: CacheManager

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

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

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

      Specified by:
      enableAll in interface CacheManager
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: CacheManager

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

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

      Specified by:
      isEnabled in interface CacheManager
      Returns:
      true 若總閘為啟用
    • disableCache

      public void disableCache(String name)
      Description copied from interface: CacheManager

      停用指定名稱的單一快取

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

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

      Specified by:
      disableCache in interface CacheManager
      Parameters:
      name - 快取名稱
    • enableCache

      public void enableCache(String name)
      Description copied from interface: CacheManager

      啟用指定名稱的單一快取

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

      Specified by:
      enableCache in interface CacheManager
      Parameters:
      name - 快取名稱
    • isCacheEnabled

      public boolean isCacheEnabled(String name)
      Description copied from interface: CacheManager

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

      預設實作回 CacheManager.isEnabled()

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

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