I'm planning to use Redis for caching. Beside basic caching, there is a special requirement: solution must be capable of invalidating cached items by "extra keys"; these are collection of business entity types with id, practically KVPs. Example: client:12345 or account:4567. There can be multiple KVPs associated to a cache item and cache invalidation can be invoked with only providing a KVP collection. Only those items are subjects for invalidation that match all given extra key criteria (in one step).
I'm thinking of combining standard cache with sets, like the following:
- Storing items:
SET key1 value1,SET key2 value2 - Storing extra keys:
SADD client:1234 key1 key2,SADD account:4567 key2,SADD card:987 key2 - Invalidation by extra key: delete all keys given by
SMEMBERS account:4567thenDEL account:4567 - Invalidation by extra keys: delete all keys given by
SINTER account:4567 client:1234, thenSREMthem from account:4567 and client:1234
Is it good enough (in terms of performance and stability), or there is a better way to do this?