Skip to content

PageManager.beforeCached

PageManager.beforeCached is an event on the Event Bus that occurs whenever a Turbo.before-cache event is fired in a page. To read more about Turbo visit the Page Manager Api documentation

Event body

none

Example

In this example we listen to PageManager.beforeCached event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('PageManager.beforeCached', () => {
        console.log('This fires before the current page is saved to cache');
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past PageManager.beforeCached events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    const pastBeforeCachedEvents = messageStorageApi.getChannelMessages('PageManager.beforeCached');

    if (pastBeforeCachedEvents.length > 0) {
        pastBeforeCachedEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference