mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
27 lines
629 B
JavaScript
27 lines
629 B
JavaScript
import BLOG from '@/blog.config'
|
||
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)
|
||
}
|