Next.js Discord

Discord Forum

Caching data across paths

Unanswered
Palomino posted this in #help-forum
Open in Discord
Avatar
PalominoOP
Hello πŸ‘‹
I've been trying out various caching options for my app (including unstable_cache and fetch cache), though it seems they only cache their return values on a per-path basis. When navigating between different paths, data is always fetched anew.
I do perform a few slower api calls that are common across multiple paths in my app (such as querying whether a github repo is public) and these operations can take up quite significant time (~1s), so I'd prefer reusing the reuslt whenever possible.
Is there a built-in way of persisting data across routes? Should I opt for an external cache such as Redis?

Node version used: 14.2.5

2 Replies

Avatar
yea, you can use both: unstable_cache and fetch cache and add tags to it. With these tags the data will be saved inside the data cache and are cached across multiple paths
Avatar
@Palomino solved?