Files
NotionNext/lib/cache/cache_manager.js
tangly1024 2c07a79d1e feature:
layout优化,图片优化
2021-12-23 14:59:38 +08:00

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