vue服务端渲染缓存应用详解( 二 )

const LRU = require('lru-cache')

const microCache = LRU({

max: 100, // 最大缓存的数目

maxAge: 1000 // 重要提示:条目在 1 秒后过期。

})

const isCacheable = req => {

//判断是否需要页面缓存

if (req.url && req.url === '/') {

return req.url

} else {

return false

}

}

app.get('*', (req, res) => {

const cacheable = isCacheable(req)

if (cacheable) {

const hit = microCache.get(req.url)

推荐阅读