Files
NotionNext/lib/cache/cache_manager.js
tangly1024 dfc0f645d4 Code🤣
2021-09-27 09:33:21 +08:00

22 lines
584 B
JavaScript

import { getCacheFromFile, setCacheToFile } from '@/lib/cache/local_file_cache'
import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache'
import BLOG from '@/blog.config'
export async function getDataFromCache (key) {
let dataFromCache
if (BLOG.isProd) {
dataFromCache = await getCacheFromMemory(key)
} else {
dataFromCache = await getCacheFromFile(key)
}
return dataFromCache
}
export async function setDataToCache (key, data) {
if (BLOG.isProd) {
await setCacheToMemory(key, data)
} else {
await setCacheToFile(key, data)
}
}