Files
NotionNext/lib/cache/cache_manager.js
2022-04-11 13:00:16 +08:00

34 lines
841 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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'
const enableCache = true
/**
* 为减少频繁接口请求notion数据将被缓存
* @param {*} key
* @returns
*/
export async function getDataFromCache(key) {
if (!enableCache) {
return null
}
const dataFromCache = await getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
return dataFromCache
}
export async function setDataToCache(key, data) {
if (!enableCache || !data) {
return
}
await setCache(key, data)
}
export async function delCacheData(key) {
if (!enableCache) {
return
}
await delCache(key)
}