当前位置:网站首页>next.js Implement server side cache

next.js Implement server side cache

2020-11-08 09:41:52 Cheng Xiaolei

nextjs Use memory-cache Plug in to achieve server side caching

import cacheData from 'memory-cache';

async function putCache(url, options) {  // url Identify for cache 
    const value = cacheData.get(url); //  Access to the cache 
    if (value) {
     //  If you have a cache  
      *codeing*
    } else {
        const hours = 24;  
      //  Request interface   obtain data
        cacheData.put(url, data, hours * 1000 * 60 * 60); // url  Identify for cache    data For data    The third parameter is the time in milliseconds 
        return data;
    }
}

版权声明
本文为[Cheng Xiaolei]所创,转载请带上原文链接,感谢