Skip to content

Cache

In-memory key-value cache with TTL support.

4 modules

ModuleDescription
快取清除清除所有快取項目或按模式篩選
快取刪除根據鍵刪除快取項目
快取獲取根據鍵從快取中獲取值
快取設定在快取中設定值,可選擇 TTL

Modules

快取清除

cache.clear

清除所有快取項目或按模式篩選

Parameters:

NameTypeRequiredDefaultDescription
patternstringNo*匹配鍵的全域模式(例如 "user:",預設 "" 清除所有)
backendstringNomemory使用的快取後端
redis_urlstringNoredis://localhost:6379Redis 連線 URL

Output:

FieldTypeDescription
cleared_countnumber清除的快取項目數量
backendstring使用的後端

快取刪除

cache.delete

根據鍵刪除快取項目

Parameters:

NameTypeRequiredDefaultDescription
keystringYes-要刪除的快取鍵
backendstringNomemory使用的快取後端
redis_urlstringNoredis://localhost:6379Redis 連線 URL

Output:

FieldTypeDescription
keystring快取鍵
deletedboolean鍵是否找到並刪除
backendstring使用的後端

快取獲取

cache.get

根據鍵從快取中獲取值

Parameters:

NameTypeRequiredDefaultDescription
keystringYes-要查找的快取鍵
backendstringNomemory使用的快取後端
redis_urlstringNoredis://localhost:6379Redis 連線 URL

Output:

FieldTypeDescription
keystring快取鍵
valueany快取的值(若未找到則為 null)
hitboolean是否在快取中找到鍵
backendstring使用的後端

快取設定

cache.set

在快取中設定值,可選擇 TTL

Parameters:

NameTypeRequiredDefaultDescription
keystringYes-要儲存值的快取鍵
valuestringYes-要快取的值(任何可 JSON 序列化的值)
ttlnumberNo0存活時間(秒)(0 = 不過期)
backendstringNomemory使用的快取後端
redis_urlstringNoredis://localhost:6379Redis 連線 URL

Output:

FieldTypeDescription
keystring快取鍵
storedboolean值是否成功儲存
ttlnumberTTL 秒數(0 = 不過期)
backendstring使用的後端

Released under the Apache 2.0 License.