My question is whether a publish of the page is expected to invalidate the cache? Or should I expect the newly published update to an active page will take up to 3600 seconds to reflect through this API request?
When using cacheSeconds and staleCacheSeconds with the Content API in Builder.io, the behavior of cache invalidation aligning with page publishes can be understood better through the documentation.
Cache Invalidation on Publish
When you publish a page, it ideally should invalidate the cache to reflect the latest changes. However, there are nuances to this process:
Cache Control withcacheSecondsandstaleCacheSeconds:
cacheSeconds: This sets the maximum age of the cache-control header response header. A higher value can improve performance by reducing frequent fetch requests.
staleCacheSeconds: This leverages stale-while-revalidate for serving stale responses while updating the cache in the background for maximum performance.
Expected Behavior on Publish
Publishing new content or updates to an existing page typically should invalidate the cache immediately so that the latest changes are available to end-users without waiting for the specified cache duration:
Content Fetching and Cache Invalidations:
If you have set cacheSeconds to 3600 seconds and staleCacheSeconds to 3600 seconds, a newly published page should ideally reflect immediately due to cache invalidation triggered by publishing action.
Practical Expectation:
Realistically, there might be slight delays before the edge cache updates propagate completely. But stale-while-revalidate ensures that even if there is cached content available, it fetches the latest in the background and updates the cache.
Example:
Your current code with cacheSeconds and staleCacheSeconds setup: