2 Replies Latest reply on Dec 27, 2014 2:33 PM by Hristo Stoyanov

    Infinispan newbie question - per-user data caches design

    Hristo Stoyanov Master

      Hi. I am new to Infinispan and have a basic design question:

      I need to maintain per-user cache in my WildFly server and be able to purge user's cache on demand (outside any eviction policy). I can have thousands of uses.

      If I keep a single global cache, I can cache user-specific data by prefixing the cache string keys with the user id (which are unique). However, purging the data for a specific user is

      not quite easy given the Cache API - I basically have to iterate over all entries (thousands) and remove the ones belonging to the user every time user data is to be purged.


      Therefore I contemplate two alternatives:


      1. I can create per-user caches (using the EmbeddedCacheManager API) where the cache name is the user id. Then it is easy to clean up user's cache. But would it scale with thousands of users/caches?


      2. I can use the TreeCache API. I store the user's data at a user-specific parent tree node. The TreeCache API has the ability to purge a sub-tree, therefore I can clean up user's data easily. But I am under the impression that TreeCache API is somewhat of a legacy stuff for previous JBoss Cache users , so the same should be achievable with just the vanilla Infinispan Cache API (possible as outlines in 1.)


      3. I could use the Query API,  but it seems tailored for searching specific classes by their attributes. I basically want to purge everything under a user id (the key).


      So, is 1., 2. or 3. the better way of maintaining per-user caches, or there is something else I am missing? My current thinking is 1. is best for my use case, but will it scale?