mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
perf(优化Vercel中的缓存行为): 去除在Vercel环境中无意义的缓存读写
This commit is contained in:
10
lib/cache/cache_manager.js
vendored
10
lib/cache/cache_manager.js
vendored
@@ -2,13 +2,19 @@ import BLOG from '@/blog.config'
|
||||
import FileCache from './local_file_cache'
|
||||
import MemoryCache from './memory_cache'
|
||||
|
||||
// 配置是否开启Vercel环境中的缓存,因为Vercel中现有两种缓存方式在无服务环境下基本都是无意义的,纯粹的浪费资源
|
||||
const enableCacheInVercel =
|
||||
process.env.npm_lifecycle_event === 'build' ||
|
||||
process.env.npm_lifecycle_event === 'export' ||
|
||||
!BLOG['isProd']
|
||||
|
||||
/**
|
||||
* 为减少频繁接口请求,notion数据将被缓存
|
||||
* @param {*} key
|
||||
* @returns
|
||||
*/
|
||||
export async function getDataFromCache(key, force) {
|
||||
if (BLOG.ENABLE_CACHE || force) {
|
||||
if (enableCacheInVercel || BLOG.ENABLE_CACHE || force) {
|
||||
const dataFromCache = await getApi().getCache(key)
|
||||
if (!dataFromCache || JSON.stringify(dataFromCache) === '[]') {
|
||||
return null
|
||||
@@ -21,7 +27,7 @@ export async function getDataFromCache(key, force) {
|
||||
}
|
||||
|
||||
export async function setDataToCache(key, data, customCacheTime) {
|
||||
if (!data) {
|
||||
if (!enableCacheInVercel || !data) {
|
||||
return
|
||||
}
|
||||
// console.trace('[API-->>缓存写入]:', key)
|
||||
|
||||
Reference in New Issue
Block a user