.net-8.0hybridcachefusion-cache

Removing multiple keys at once with FusionCache


The title is not precise as I don't want to remove arbitrary keys at once.

My scenario is as fallows: I need to cache roles by user and users by roles. So I have keys that have userid and role set in value, and vice versa. Now there is a mapping between roles and auth claims. One claim maps to many roles. If that mapping changes I want to evict all affected users and roles.

I started with HybridCache, but I am really missing many Features that FusionCache offers. Still, HybridCache has the tags. And has eviction by tag. Using the tags I can tag users and roles by the original claim and evict them with one+one shot.

How can I achieve the same with FusionCache?

The only workaround I can imagine is reading both the original and the new role set from cache, unioning all users from these and remove both role keys and all affected user keys. But I have concerns about the non-transactional manner of this interaction as there can be quite a lot of calls to do to the cache. Whilst there would be only two with tags.

Related: https://github.com/ZiggyCreatures/FusionCache/issues/319


Solution

  • FusionCache creator here.

    As you already mentioned at the end, the solution is Tagging, which is coming soon.

    How soon? I think a first preview version will be out in a matter of a week or two.

    Hope this helps.

    ps: the part "but I am really missing many Features that FusionCache offers" is really appreciated 🙂.