详情页服务器请求加缓存
This commit is contained in:
33
plugins/cache.server.js
Normal file
33
plugins/cache.server.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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(),
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
// import NodeCache from 'node-cache';
|
||||
|
||||
// const cache = new NodeCache({ stdTTL: 3600 }); // 缓存有效期 1 小时
|
||||
|
||||
// export default defineNuxtPlugin((nuxtApp) => {
|
||||
// return {
|
||||
// provide: {
|
||||
// cache
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
Reference in New Issue
Block a user