Class EhcacheCacheAdapter<K,V>

java.lang.Object
io.leandev.appfuse.cache.adapter.ehcache.EhcacheCacheAdapter<K,V>
Type Parameters:
K - 鍵的型別
V - 值的型別
All Implemented Interfaces:
Cache<K,V>

public class EhcacheCacheAdapter<K,V> extends Object implements Cache<K,V>

Ehcache 快取適配器

實作 Cache 介面,包裝 Ehcache 3.x Cache。

設計原則

  • Adapter 層保持簡單,只提供基本快取操作
  • disable/enable 功能由 ManagedCache 層提供
  • 完整統計資訊由 CacheMonitor 層記錄

欄位說明

  • cacheManager: 保留供未來擴充使用(如持久化偵測、進階統計)
Since:
1.0
  • Constructor Details

    • EhcacheCacheAdapter

      public EhcacheCacheAdapter(org.ehcache.Cache<K,V> ehcache, CacheConfiguration<K,V> configuration, org.ehcache.CacheManager cacheManager)
      建構子
      Parameters:
      ehcache - Ehcache 快取實例
      configuration - 快取配置
      cacheManager - Ehcache 管理器(保留供未來擴充)
  • Method Details

    • get

      public V get(K key)
      Description copied from interface: Cache
      取得快取值
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 鍵
      Returns:
      快取值,若不存在或快取已停用則返回 null
    • put

      public void put(K key, V value)
      Description copied from interface: Cache
      寫入快取
      Specified by:
      put in interface Cache<K,V>
      Parameters:
      key - 鍵
      value - 值
    • remove

      public void remove(K key)
      Description copied from interface: Cache
      移除快取項目
      Specified by:
      remove in interface Cache<K,V>
      Parameters:
      key - 鍵
    • clear

      public void clear()
      Description copied from interface: Cache
      清空所有快取項目
      Specified by:
      clear in interface Cache<K,V>
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: Cache
      檢查快取是否包含指定鍵
      Specified by:
      containsKey in interface Cache<K,V>
      Parameters:
      key - 鍵
      Returns:
      true 若包含該鍵
    • disable

      public void disable()
      Description copied from interface: Cache

      停用快取

      停用後:

      • get() 操作返回 null
      • put() 操作被忽略
      • 已存在的資料保留
      • 可透過 enable() 重新啟用
      Specified by:
      disable in interface Cache<K,V>
    • enable

      public void enable()
      Description copied from interface: Cache
      啟用快取
      Specified by:
      enable in interface Cache<K,V>
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: Cache
      檢查快取是否已啟用
      Specified by:
      isEnabled in interface Cache<K,V>
      Returns:
      true 若快取已啟用
    • getStatistics

      public CacheStatistics getStatistics()
      Description copied from interface: Cache
      取得快取統計資訊
      Specified by:
      getStatistics in interface Cache<K,V>
      Returns:
      統計資訊
    • getStatus

      public CacheStatus getStatus()
      Description copied from interface: Cache
      取得快取狀態
      Specified by:
      getStatus in interface Cache<K,V>
      Returns:
      狀態資訊
    • getName

      public String getName()
      Description copied from interface: Cache
      取得快取名稱
      Specified by:
      getName in interface Cache<K,V>
      Returns:
      快取名稱
    • getConfiguration

      public CacheConfiguration<K,V> getConfiguration()
      Description copied from interface: Cache
      取得快取配置
      Specified by:
      getConfiguration in interface Cache<K,V>
      Returns:
      配置資訊
    • getEhcache

      public org.ehcache.Cache<K,V> getEhcache()
      取得底層 Ehcache 實例(供內部使用)
      Returns:
      Ehcache 快取實例