Files
NotionNext/lib/cache/cache_manager.js
tangly1024 f6f0e9d41a feature:
广告、缓存
2021-12-17 21:21:44 +08:00

26 lines
596 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, setCacheToMemory } from '@/lib/cache/memory_cache'
const enableCache = true // 生产环境禁用
/**
* 为减少频繁接口请求notion数据将被缓存
* @param {*} key
* @returns
*/
export async function getDataFromCache (key) {
if (!enableCache) {
return null
}
const dataFromCache = await getCacheFromMemory(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
return dataFromCache
}
export async function setDataToCache (key, data) {
if (!enableCache || !data) {
return
}
await setCacheToMemory(key, data)
}