feat(使用const 直接引入缓存实现类): 避免多次调用判断

This commit is contained in:
anime
2025-01-04 15:06:13 +08:00
parent b93944fe8f
commit 732c16d717

View File

@@ -15,7 +15,7 @@ const enableCacheInVercel =
*/
export async function getDataFromCache(key, force) {
if (enableCacheInVercel || BLOG.ENABLE_CACHE || force) {
const dataFromCache = await getApi().getCache(key)
const dataFromCache = await cacheApi.getCache(key)
if (!dataFromCache || JSON.stringify(dataFromCache) === '[]') {
return null
}
@@ -31,24 +31,15 @@ export async function setDataToCache(key, data, customCacheTime) {
return
}
// console.trace('[API-->>缓存写入]:', key)
await getApi().setCache(key, data, customCacheTime)
await cacheApi.setCache(key, data, customCacheTime)
}
export async function delCacheData(key) {
if (!JSON.parse(BLOG.ENABLE_CACHE)) {
return
}
await getApi().delCache(key)
await cacheApi.delCache(key)
}
/**
* 缓存实现类
* @returns
*/
function getApi() {
if (process.env.ENABLE_FILE_CACHE) {
return FileCache
} else {
return MemoryCache
}
}
// 缓存实现类
const cacheApi = process.env.ENABLE_FILE_CACHE ? FileCache : MemoryCache