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

Published responses cached regardless of caching settings #952

Open
1 task done
nathobson opened this issue Oct 22, 2024 · 4 comments
Open
1 task done

Published responses cached regardless of caching settings #952

nathobson opened this issue Oct 22, 2024 · 4 comments
Assignees
Labels
bug [Issue] Something isn't working

Comments

@nathobson
Copy link

nathobson commented Oct 22, 2024

Describe the issue you're facing

Responses from the Storyblok API are cached when retrieving published content, even when apiOptions contains a cache type of none.

Reproduction

https://stackblitz.com/edit/withastro-astro-971qsd?file=.env

Steps to reproduce

Using Astro in SSR mode via output: 'server' and the Node adapter in mode: standalone, responses from the Storyblok API are cached when retrieving published content, even when apiOptions contains a cache type of none.

For example, the following call via useStoryblok() will return the cached response, not reflecting any updated (published) content:

const story = await useStoryblok(`cdn/stories/home`, {
    version: "published",
  }
)

I've also tested with the settings as in playground-ssr in the repo, which has the following settings:

apiOptions: {
  cache: {
    clear: "auto",
    type: "memory",
  },
}

This produced the same result.

However, if the exact same useStoryblok() call is set to retrieve drafts, everything updates when the page is refreshed, including draft and published content:

const story = await useStoryblok(`cdn/stories/home`, {
    version: "draft",
  }
)

There appears to be a closed and merged PR from three weeks ago in the storyblok-js-client repo but for whatever reason, this doesn't seem to have fixed the issue in the Storyblok Astro SDK.

Tested with the latest release (v5.0.2) of @storyblok/astro, which appears to contain the latest release of storyblok/storyblok-js-client from looking at the version installed in node_modules.

System Info

System:
    OS: macOS 15.0.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 66.47 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    bun: 1.0.22 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 130.1.71.114
    Chrome: 129.0.6668.103
    Safari: 18.0.1
    Safari Technology Preview: 18.0

Used Package Manager

npm

Error logs (Optional)

No response

Validations

@nathobson nathobson added pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Oct 22, 2024
@J05HI
Copy link

J05HI commented Dec 20, 2024

Any news here @dipankarmaikap ?

I am using the new content layer feature and getting the same problem.
If I unpublish a page it is still in the collection. I have disabled the cache.
Here's my content/config:

import {storyblokLoader} from '@storyblok/astro';
import {defineCollection} from 'astro:content';
import StoryblokApi from '../utils/StoryblokApi';


const storyblokCollection = defineCollection({
    loader: storyblokLoader({
        accessToken: import.meta.env.STORYBLOK_TOKEN,
        version: StoryblokApi.getVersion(),
        apiOptions: {
            cache: {
                type: 'none',
            },
        },
    }),
});

export const collections = {
    storyblok: storyblokCollection,
};

@J05HI
Copy link

J05HI commented Dec 20, 2024

Replacing the same asset with a new version (for example when using the storyblok web image editor) the cache does not get refreshed too.

@dipankarmaikap
Copy link
Contributor

Hi @J05HI,

Thank you for reporting this! Please note that the Storyblok Astro Content Layer API is still in its early experimental phase. We wouldn’t recommend using it in production just yet, but we truly appreciate you trying it out and providing feedback to help us improve.

@dipankarmaikap dipankarmaikap added bug [Issue] Something isn't working and removed pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Jan 14, 2025
@dipankarmaikap dipankarmaikap self-assigned this Jan 14, 2025
@edodusi
Copy link
Contributor

edodusi commented Jan 17, 2025

Hi @nathobson, the behavior you are facing reflects the current cache behavior in Storyblok, it's not that something isn't working, it's actually how it's supposed to work.

The storyblok-js-client is trying to offer users tools to implement a custom caching strategy, but in order to benefit from it you have to first understand how it works and what are these tools.

I tried to cover everything in this FAQ page: https://www.storyblok.com/faq/how-stories-are-cached-content-delivery-api

This should give you many possibilities to implement your own strategies. As stated in the FAQ, you can always bypass the cache helpers in the client, if you understand the impact on the rate limits.

I hope this helps.

cc @J05HI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [Issue] Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants