Skip to content

Tag based invalidation #1640

@cupofjoakim

Description

@cupofjoakim

Picking up from #120. That was on the old cache-manager and closed without anything landing. The rewrite has hooks and L1/L2 now, which I think gets around Bryan's "not generic enough" concern.

Use case is content caches: one upstream entity referenced by many cache entries, need to purge all of them when it changes. Right now that means walking the dependency graph or maintaining a Redis SET by hand. Same thing Symfony's TagAwareAdapter and Next.js revalidateTag do.

await cache.set(key, value, {tags: ['entity:42']})
await cache.invalidateTag('entity:42')

The BEFORE_SET / AFTER_SET hooks look like the right spot. Tag index can just be cache entries under a reserved prefix, no adapter changes. Would need to clear both primary and secondary, and probably go through sync for multi-instance.

Happy to PR if you're up for it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions