AWS
Overrides
Tag Cache

This override is used by the cache adapter (opens in a new tab) that is provided by OpenNext to the NextServer. It is also used by OpenNext if enableCacheInterception is set to true in the configuration and by the initializationFunction for prepopulating the cache.

It is used for the cache tags (i.e. revalidateTag and revalidatePath). It does not handle anything related to the ISR/SSG cache or the fetch cache used by Next.js. It's main role is to detremine if a path is stale based on the tags and also to update the tag cache when revalidateTag is called.

The current implementation differs from the way Next.js standalone handle cache tags. In the standalone version, the cache tags are stored in a file, and every time a cache entry is accessed, it has to check for every tags if the entry is stale. This approach is very read heavy and doesn't work well with DB like DynamoDB. We choose to go another way. We store tags for every path that exists in the cache. This way, we can easily know if a path is stale by just checking the path instead of every tags used. This approach is more write heavy but it's a tradeoff we are willing to make. This also has the drawback of needing to prepopulate the cache with all the tags that are used in the application. This is done by the initializationFunction.

We might allow to choose how cache tags are handled in the future depending on the TagCache implementation. If you need this feature, feel free to open an issue on the GitHub repository (opens in a new tab).

If you want to better understand how to implement your own TagCache, the easiest way would be to take a look at the existing included TagCache (opens in a new tab).