lapsus
lapsus

Reputation: 3035

Distributed Object Caching Frameworks and key based dependencies

I have been looking at several caching frameworks. Namely Memcached/Couchbase, AppFabric, Redis, MongoDB

Okay.. some of them are in fact caching frameworks others are "document stores".

Now here comes the question... I often run into situations where I simply don't know all the cache keys (for example all cached products) but for example I want to make sure all cached products are being evicted. With Runtime.MemoryCache I can use key-based dependencies which allows me for example to create a "products" key and all other products use this key as a dependency. Now whenever I remove "products" all keys related to this key are being evicted too.

Unfortunately MongoDB, Couchbase and Redis don't come with such functionality. At least I couldn't find any information about it. Redis has the KEYS (http://redis.io/commands/keys) command but the documentation tells you not to use it in production environments.

AppFabric is able to handle dependencies but has other short comings. E.g. if you use Tags (used as dependencies) you have to use regions as well. If you use regions however you lose high availability.

Anyway... my question is: Is this a very uncommon scenario to require those kind of dependencies or is it a shortcoming for those databases/caching frameworks I put to evaluation?

Upvotes: 4

Views: 899

Answers (1)

Andy H
Andy H

Reputation: 132

To answer your question simply: it is the short-coming of the caching frameworks you put to test and also that it is not an uncommon scenario to want those kind of dependencies. In fact, any viable caching solution must have, at the minimum, the ability to synchronize with a relational or non relational data store.

Key-based dependency, as you mention, associates one cached item with another item in the cache. It invalidates the dependent item when that particular item changes. Whenever that item is removed or updated from the cache, associated object will be expired. Key based dependency is cascaded. For example, if key1 depends on key2, key2 depends on key3 and key3 depends on key4, then removal of key4 will result in expiration of key1, key2 and key3.

Apart from Key-Based dependencies, there are other dependencies you can make use of like File-Based (make your cached Object dependent on an external file and if the file is updated or removed, the dependent object in the cache is removed), Database Dependency (synchronize cached items with database, so any changes in the database removes the dependent cached objects from the cache), Custom Dependency (you can expire objects based on your application logic).

NCache is one such product that provides a complete set of dependency features according to your application requirements.

Upvotes: 3

Related Questions