Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Isr should have the ability to dynamically adjust the key used to store the cache instead of always using the url of the request #1604

Closed
@DeVmend

Description

@DeVmend

Problem Solved By The Feature

If you want to cache a page in different variants on the server side, e.g. a variant for logged-in and non-logged-in users, or for different viewports, this cannot be implemented with one cache per URL.

In such scenarios, the page cached in another variant would lead to a content shift or flickering when loading the page.

Solution

Provide a factory method that allows to modify the key used to store the cache.

For example:

    const isr = new ISRHandler({
        indexHtml,
        invalidateSecretToken: process.env['INVALIDATE_TOKEN'] || 'MY_TOKEN',
        enableLogging: false,
        cacheKeyFactory: (req: Request) => {
            if (req.cookies && req.cookies.access_token) {
                return `${$req.url}%authenticated`;
            }
            return req.url;
        }
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions