Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache entire rendered response #192

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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