AppFabric Cache 'Design' - caching individual items or collections?

We are in the process of scaling up one of our web applications from one server to a web farm. Currently, the application uses the Http cache to cache the reference data for the application. The data is "similar" to the product catalog:

  • categories (i.e. list)
  • (i.e. list)

Since data is updated very rarely, we also pre-compute some search queries

  • ProductsByCategory (i.e. dictionary)

Collections are currently cached as whole objects ... i.e. the entire list / dictionary receives and sets. Collections are usually used, since I usually need to pop up drop-down lists / lists / etc.

The reference data must be synchronized between the farm servers. Enter AppFabric ...

  • Is our previous caching model suitable for AppFabric caching? The examples I came across seem to put a single item in the cache, rather than entire collections (with "areas" used for bulk retrieval operations)

  • What is the best way, if at all, to update reference data β€œtogether” ... i.e. if the categories are updated, I need updated products to reflect the latest categories.

+5
source share
2 answers

Support for the "bulk put'-type" operation is a bit, but limited at the moment (read: nonexistent). But a little thought suggests that this is probably correct - if you threw a collection of objects into the cache, he would not know how to give them meaningful keys or tags (of which more at one moment). You could fake it using the extension method, which took a collection of objects and looked, perhaps, at the Name or Id property on each object to put objects in the cache, but under covers it still comes down to putting objects in the cache one at a time.

However, to get a set of objects from the cache, there is another option to the GetObjectsInRegion(regionname) method. If at the point where the object is inserted into the cache, you add a tag to it, for example. for a product, mark it with a category, later you can return all the objects for a specific tag using the GetObjectsByTag method. The great thing (I think) about using tags is that you can put any number of them in an object in the cache, for example. for a product, you can mark it with a category, as well as a supplier and, say, a price range. This gives you great flexibility in how you can request your cached items - you can request any single tag or you can make AND / OR requests using the GetObjectsByAllTags / GetObjectsByAnyTag .

+2
source

I found the same problem myself. Use local cache, use individual objects in a region, and use regional-level notification callbacks

+1
source

Source: https://habr.com/ru/post/887395/


All Articles