0
votes

Is there any way that I can put objects into the cache with a dependency?

For example if I put ObjectB into the cache with a dependency on ObjectA so that when ObjectA expires or I remove it ObjectB will also automatically be removed?

I know that I can create regions and tag items that way to create my dependency but I don't really want to do this as Regions exist on only one cache server in the cluster which kind of defeats the point of a distributed and scalable caching solution.

If I can't add with a straight out dependency I'm thinking I could possibly work around it by adding my objects with some kind of key naming convention to create the dependencies.

eg. Add ObjectA with key 'ObjectA'
Add ObjectB with key 'ObjectA_ObjectB'

but then when I want to expire all the objects dependant on ObjectA I would need to fetch based on a wildcard search of the key. Is this possible?

2

2 Answers

1
votes

No, right now there is no support in the AppFabric API for dependencies. Unfortunately, neither is there a way to search through the keys in the way you suggest :-(

0
votes

Although AppFabric is free, but this initial cost advantage isn't very fruiteful if you want to build scalable applications as App Fabric does not have a lot of features, like DB dependency features.

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 that is a distributed caching software is one such product that provides a complete set of dependency features according to your application requirements.