Skip to content

Conversation

@waydelyle
Copy link
Contributor

Enable the ability to cache the entire rendered response, enable custom TTL per URL and enable per request ability to enable or disable cache.

@waydelyle waydelyle closed this May 7, 2020
@waydelyle waydelyle reopened this May 7, 2020
@almunnings
Copy link

This can also be achieved through a middleware such as express-cache-middleware, in your vue.config.js, for example:

config.pluginOptions.ssr.extendServer = (app) => {
  const ExpressCache = require('express-cache-middleware')
  const cacheManager = require('cache-manager')

  const cacheStore = cacheManager.caching({
    store: 'memory', ...config.pluginOptions.ssr.lruCacheOptions
  })

  const expressCache = new ExpressCache(cacheStore)
  const defaultCacheRoute = expressCache.cacheRoute

  // Cache conditions.
  expressCache.cacheRoute = async (req, res, next) => {
    const cookies = req.headers?.cookie || ''

    if (!cookies.includes('auth-token')) {
      await defaultCacheRoute.call(expressCache, req, res, next)
    } else {
      next()
    }
  }

  expressCache.attach(app)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants