storyblok-js-client icon indicating copy to clipboard operation
storyblok-js-client copied to clipboard

flushCache() not working

Open gutisalex opened this issue 1 year ago • 3 comments

I have the problem (only on production not on staging) that whenever I change a story (Title for example) it takes ages to be reflected on the webpage! I am using version=published with a public token. I know there is some caching in place, so I added a server middleware to my nuxt app which is supposed to flush the cache manually using Storyblok.flushCache().

const bodyParser = require('body-parser')
const app = require('express')()
const StoryblokClient = require('storyblok-js-client')
const logger = require('pino')()

const Storyblok = new StoryblokClient({
  accessToken: process.env.STORYBLOK_ACCESS_TOKEN,
})

app.use(bodyParser.json())
app.post('/reset_cms_cache', async (req, res) => {
  logger.debug({ msg: `RUNTIME TRYING RESET STORYBLOK CACHE` })
  await Storyblok.flushCache().then(() =>
    logger.info({ msg: `RUNTIME RESET STORYBLOK CACHE SUCCESSFUL` })
  )
  res.json({ reset: true })
})

module.exports = app

The idea is to use the webhook option in storyblok to call that whenever something has been published. I try to call the url via postman first for testing but unfortunately this doesn't work. Changes are not being visible in the frontend... The weird thing though I don't need manual flushing on staging at all. When I change the title, refresh the page, it is immediately changed! We use two separate spaces for staging and production. We use storyblok v2 for staging and v1 for production. Any idea what could be the issue here?

gutisalex avatar Oct 19 '22 06:10 gutisalex

Hello @gutisalex I'll take a look on that. Thanks for the heads up.

thiagosaife avatar Oct 21 '22 16:10 thiagosaife

I just checked on a story again. If I change the title and use postman to get the story I will get the updated title. But using the js client I figured it will still use an old cv when fetching the data. The request always shows an older cv. I thought its handling the cv automatically?! Or am I wrong? Do I have to handle it myself? If I use the cv option and set it to a newer timestamp it works... How should I handle the cv?

gutisalex avatar Oct 22 '22 15:10 gutisalex

I might have found the solution:

  cache: {
    clear: `auto`,
    type: `memory`,
  },

That worked locally and on staging!

gutisalex avatar Oct 22 '22 19:10 gutisalex

Have this solution worked for you?

thiagosaife avatar Oct 26 '22 13:10 thiagosaife

I just checked and yes it has... thanks for your help!

gutisalex avatar Oct 27 '22 09:10 gutisalex