mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feat(使用const 直接引入缓存实现类): 避免多次调用判断
This commit is contained in:
19
lib/cache/cache_manager.js
vendored
19
lib/cache/cache_manager.js
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user