storyblok-js-client
storyblok-js-client copied to clipboard
flushCache() not working
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?
Hello @gutisalex I'll take a look on that. Thanks for the heads up.
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?
I might have found the solution:
cache: {
clear: `auto`,
type: `memory`,
},
That worked locally and on staging!
Have this solution worked for you?
I just checked and yes it has... thanks for your help!