mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-21 15:09:43 +00:00
本地开发、开启文件缓存
This commit is contained in:
17
lib/cache/cache_manager.js
vendored
17
lib/cache/cache_manager.js
vendored
@@ -1,7 +1,14 @@
|
||||
import { getCacheFromMemory as getCache, setCacheToMemory as setCache, delCacheFromMemory as delCache } from '@/lib/cache/memory_cache'
|
||||
// import { getCacheFromFile as getCache, setCacheToFile as setCache, delCacheFromFile as delCache } from './local_file_cache'
|
||||
import MemoryCache from './memory_cache'
|
||||
import FileCache from './local_file_cache'
|
||||
const enableCache = true
|
||||
|
||||
let api
|
||||
if (process.env.ENABLE_FILE_CACHE) {
|
||||
api = FileCache
|
||||
} else {
|
||||
api = MemoryCache
|
||||
}
|
||||
|
||||
/**
|
||||
* 为减少频繁接口请求,notion数据将被缓存
|
||||
* @param {*} key
|
||||
@@ -11,7 +18,7 @@ export async function getDataFromCache(key) {
|
||||
if (!enableCache) {
|
||||
return null
|
||||
}
|
||||
const dataFromCache = await getCache(key)
|
||||
const dataFromCache = await api.getCache(key)
|
||||
if (JSON.stringify(dataFromCache) === '[]') {
|
||||
return null
|
||||
}
|
||||
@@ -22,12 +29,12 @@ export async function setDataToCache(key, data) {
|
||||
if (!enableCache || !data) {
|
||||
return
|
||||
}
|
||||
await setCache(key, data)
|
||||
await api.setCache(key, data)
|
||||
}
|
||||
|
||||
export async function delCacheData(key) {
|
||||
if (!enableCache) {
|
||||
return
|
||||
}
|
||||
await delCache(key)
|
||||
await api.delCache(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user