mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-03 15:10:19 +00:00
缓存切换
This commit is contained in:
18
lib/cache/cache_manager.js
vendored
18
lib/cache/cache_manager.js
vendored
@@ -1,33 +1,33 @@
|
|||||||
import { getCacheFromMemory, setCacheToMemory, delCacheFromMemory } from '@/lib/cache/memory_cache'
|
import { getCacheFromMemory as getCache, setCacheToMemory as setCache, delCacheFromMemory as delCache } from '@/lib/cache/memory_cache'
|
||||||
// import { getCacheFromFile, setCacheToFile, delCacheFromFile } from './local_file_cache'
|
// import { getCacheFromFile as getCache, setCacheToFile as setCache, delCacheFromFile as delCache } from './local_file_cache'
|
||||||
const enableCache = true // 生产环境禁用
|
const enableCache = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为减少频繁接口请求,notion数据将被缓存
|
* 为减少频繁接口请求,notion数据将被缓存
|
||||||
* @param {*} key
|
* @param {*} key
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function getDataFromCache (key) {
|
export async function getDataFromCache(key) {
|
||||||
if (!enableCache) {
|
if (!enableCache) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const dataFromCache = await getCacheFromMemory(key)
|
const dataFromCache = await getCache(key)
|
||||||
if (JSON.stringify(dataFromCache) === '[]') {
|
if (JSON.stringify(dataFromCache) === '[]') {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return dataFromCache
|
return dataFromCache
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setDataToCache (key, data) {
|
export async function setDataToCache(key, data) {
|
||||||
if (!enableCache || !data) {
|
if (!enableCache || !data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await setCacheToMemory(key, data)
|
await setCache(key, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function delCacheData (key) {
|
export async function delCacheData(key) {
|
||||||
if (!enableCache) {
|
if (!enableCache) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await delCacheFromMemory(key)
|
await delCache(key)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user