Skip to content

Commit

Permalink
缓存切换
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Apr 11, 2022
1 parent cbb1d8a commit e3ebc00
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/cache/cache_manager.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { getCacheFromMemory, setCacheToMemory, delCacheFromMemory } from '@/lib/cache/memory_cache'
// import { getCacheFromFile, setCacheToFile, delCacheFromFile } from './local_file_cache'
const enableCache = true // 生产环境禁用
import { getCacheFromMemory as getCache, setCacheToMemory as setCache, delCacheFromMemory as delCache } from '@/lib/cache/memory_cache'
// import { getCacheFromFile as getCache, setCacheToFile as setCache, delCacheFromFile as delCache } from './local_file_cache'
const enableCache = true

/**
* 为减少频繁接口请求,notion数据将被缓存
* @param {*} key
* @returns
*/
export async function getDataFromCache (key) {
export async function getDataFromCache(key) {
if (!enableCache) {
return null
}
const dataFromCache = await getCacheFromMemory(key)
const dataFromCache = await getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null
}
return dataFromCache
}

export async function setDataToCache (key, data) {
export async function setDataToCache(key, data) {
if (!enableCache || !data) {
return
}
await setCacheToMemory(key, data)
await setCache(key, data)
}

export async function delCacheData (key) {
export async function delCacheData(key) {
if (!enableCache) {
return
}
await delCacheFromMemory(key)
await delCache(key)
}

0 comments on commit e3ebc00

Please sign in to comment.