新功能
先前版本的快取可用性較差(僅支援記憶體快取),v0.16 已重新架構,內建記憶體與 Redis 儲存,同時也支援自訂儲存。詳細使用方式請參閱 API 文件。
重大變更
Node 最低版本改為 18
Node v16 已不再維護,最低版本已改為 v18。
{
"engines": {
"node": ">=18"
}
}
快取建立方式更新
已棄用:使用 createCache 建立快取。
import { createCache } from "@nocobase/cache";
const cache = createCache();
快取現在由 CacheManager 管理,並透過 app.cacheManager 建立。
const cache = await app.cacheManager.createCache({
name: "memory", // 快取的唯一名稱
store: "memory", // 快取方法的唯一名稱
// 其他設定
max: 2000,
ttl: 60 * 1000,
});
環境變數更新
先前的快取環境變數需要 JSON 字串來設定。
CACHE_CONFIG={"storePackage":"cache-manager-fs-hash","ttl":86400,"max":1000}
新的快取環境變數設定方式:
# 預設快取方法的唯一名稱,memory 或 redis
CACHE_DEFAULT_STORE=memory
# 記憶體快取的最大項目數量
CACHE_MEMORY_MAX=2000
# Redis,可選
CACHE_REDIS_URL=redis://localhost:6379