编译优化
This commit is contained in:
tangly1024
2021-12-17 15:38:33 +08:00
parent 636d355234
commit 395f402896
7 changed files with 9 additions and 88 deletions

View File

@@ -1,8 +1,6 @@
import BLOG from '@/blog.config'
import { getCacheFromFile, setCacheToFile } from '@/lib/cache/local_file_cache'
import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache'
const enableCache = true && !BLOG.isProd // 生产环境禁用
const cacheProvider = 'memory' // ['memory','file'] 用内存或data.json做缓存
/**
* 为减少频繁接口请求notion数据将被缓存
@@ -13,17 +11,7 @@ export async function getDataFromCache (key) {
if (!enableCache) {
return null
}
let dataFromCache
switch (cacheProvider) {
case 'memory':
dataFromCache = await getCacheFromMemory(key)
break
case 'file':
dataFromCache = await getCacheFromFile(key)
break
default:
break
}
const dataFromCache = await getCacheFromMemory(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
@@ -34,14 +22,5 @@ export async function setDataToCache (key, data) {
if (!enableCache || !data) {
return
}
switch (cacheProvider) {
case 'memory':
await setCacheToMemory(key, data)
break
case 'file':
await setCacheToFile(key, data)
break
default:
break
}
await setCacheToMemory(key, data)
}