feat: 添加服务器端缓存功能并优化详情页数据获取

refactor(details/[id].vue): 重构详情页数据获取逻辑,加入缓存机制
feat(plugins/cache.server.js): 新增node-cache插件用于服务器端缓存
chore: 更新package.json依赖,添加node-cache和clone
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-07-08 11:10:20 +08:00
parent 68acefa360
commit 335d6cb1fb
48 changed files with 1758 additions and 466 deletions

View File

@@ -1,6 +1,7 @@
import { shallowReactive, reactive, effectScope, getCurrentScope, hasInjectionContext, getCurrentInstance, toRef, inject, shallowRef, isReadonly, isRef, isShallow, isReactive, toRaw, ref, computed, unref, onScopeDispose, watchEffect, readonly, nextTick, defineComponent, provide, h, watch, Suspense, Fragment, useSSRContext, defineAsyncComponent, mergeProps, onErrorCaptured, onServerPrefetch, createVNode, resolveDynamicComponent, createApp } from 'vue';
import { k as createHooks, l as getContext, h as createError$1, m as toRouteMatcher, n as createRouter, o as sanitizeStatusCode, p as executeAsync } from '../_/nitro.mjs';
import { START_LOCATION, createMemoryHistory, createRouter as createRouter$1, RouterView } from 'vue-router';
import NodeCache from 'node-cache';
import { ssrRenderComponent, ssrRenderSuspense, ssrRenderVNode } from 'vue/server-renderer';
const HASH_RE = /#/g;
@@ -1850,13 +1851,35 @@ const element_plus_injection_plugin_LfLkpoHjV8s4Q4lRVuq_y_LbzJB5vFvehZzxqpiP_nk
nuxtApp.vueApp.provide(ID_INJECTION_KEY, { "prefix": 1024, "current": 0 }).provide(ZINDEX_INJECTION_KEY, { "current": 0 });
});
const cache = new NodeCache({
stdTTL: 60,
// 默认过期时间(秒)
checkperiod: 120,
// 清理过期缓存的检查周期(秒)
maxKeys: 1e3
// 最大缓存项数量超过时LRU淘汰
});
const cache_server_7v0nz5ZjHOoH2geOvzJ1KOZtdzwpZAfyS4fAyPrxSpY = defineNuxtPlugin(() => {
return {
provide: {
cache: {
get: (key) => cache.get(key),
set: (key, value, ttl) => cache.set(key, value, ttl),
del: (key) => cache.del(key),
flush: () => cache.flushAll()
}
}
};
});
const plugins = [
unhead_dp1SxSKB06hYMJELWjNfMtwvJsT23iDY2Mk_6THvQzk,
plugin,
revive_payload_server_BXtMNu_ou6aFPdlr2yij0Fh8hzak_1_swgnvOLyyoss,
components_plugin_z4hgvsiddfKkfXTP6M8M4zG5Cb7sGnDhcryKVM45Di4,
element_plus_teleports_plugin_3k7A_fjEiCzFRl6aN3qftblOS_EZCmhIb_4gXrhvbuY,
element_plus_injection_plugin_LfLkpoHjV8s4Q4lRVuq_y_LbzJB5vFvehZzxqpiP_nk
element_plus_injection_plugin_LfLkpoHjV8s4Q4lRVuq_y_LbzJB5vFvehZzxqpiP_nk,
cache_server_7v0nz5ZjHOoH2geOvzJ1KOZtdzwpZAfyS4fAyPrxSpY
];
const defineRouteProvider = (name = "RouteProvider") => defineComponent({