Skip to content

Item written to cache by Nextjs middleware doesn't exist when reading from the cache #116

Description

@dconlisk

In a nextjs app (classic /pages setup, I'm not using the new /app directory), I want to set an item in the cache in middleware, which can then be read in my pages, components etc in the app. Unfortunately, when I try to read the value back from the cache, it is null.

i.e.:

// middleware.ts
console.log("Setting token cache entry for", guid, JSON.stringify(entry));
cache.put(guid, entry);
// index.tsx getServerSideProps method
console.log("Getting token cache entry for", guid, cache.get(guid));
const entry = cache.get(guid); // ---> entry is null

Console output:

Setting token cache entry for deab99d1-f688-4e9b-a9e49d63b049895a { ... entry object ... }
Getting token cache entry for deab99d1-f688-4e9b-a9e49d63b049895a null

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions