Class DualLayerCache<K,V>

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

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

雙層快取

結合快速層(可過期)與持久層(永不過期)的快取架構。

Since:
1.0
  • Constructor Details

    • DualLayerCache

      public DualLayerCache(Cache<K,V> fastLayer, Cache<K,V> durableLayer, String name)
      建立雙層快取
      Parameters:
      fastLayer - 快速層快取(可過期)
      durableLayer - 持久層快取(永不過期)
      name - 快取名稱
  • 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
    • get

      public V get(K key, boolean fallback)
      取得快取值(可選擇是否降級)
      Parameters:
      key - 鍵
      fallback - 是否降級至持久層
      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 若包含該鍵
    • containsKey

      public boolean containsKey(K key, boolean fallback)
      檢查快取是否包含指定鍵(可選擇是否降級)
      Parameters:
      key - 鍵
      fallback - 是否降級至持久層
      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:
      配置資訊
    • clearFastLayer

      public void clearFastLayer()
      僅清除快速層
    • clearDurableLayer

      public void clearDurableLayer()
      僅清除持久層
    • getFallbackCount

      public long getFallbackCount()
      取得降級次數
      Returns:
      降級次數
    • getFastLayer

      public Cache<K,V> getFastLayer()
      取得快速層
      Returns:
      快速層快取
    • getDurableLayer

      public Cache<K,V> getDurableLayer()
      取得持久層
      Returns:
      持久層快取