PC-mj/plugins/cache.server.js
DESKTOP-RQ919RC\Pc 335d6cb1fb feat: 添加服务器端缓存功能并优化详情页数据获取
refactor(details/[id].vue): 重构详情页数据获取逻辑,加入缓存机制
feat(plugins/cache.server.js): 新增node-cache插件用于服务器端缓存
chore: 更新package.json依赖,添加node-cache和clone
2025-07-08 11:10:20 +08:00

23 lines
649 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// plugins/cache.server.js
import NodeCache from "node-cache";
// 创建全局缓存实例
const cache = new NodeCache({
stdTTL: 60, // 默认过期时间(秒)
checkperiod: 120, // 清理过期缓存的检查周期(秒)
maxKeys: 1000, // 最大缓存项数量超过时LRU淘汰
});
export default 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(),
},
},
};
});