1

Most of caching service support to cache any object as key and value pair. But I am looking for a way that objects can be cached as regions or groups. That means, caching objects should be able to group. One or more objects are cached to a group. What ever we do (remove, update) to the group, should be affected to the objects in the group.

I searched about some caching services and found that JCS supports this. I am supposed to implement a common way as it could be used for most of caching services. Does anyone know any way or supportive resource that can be helpful?

Edit: @ cruftex: Assume an Inventory system for small shop. There are stationery items, vegetables, fruits, sweets and their prices and other details are required to be cached. What if I need to clear or do any update only for items that can be eaten (vegetable, fruits, sweets) and not to stationery and any other inedible set of objects that are cached? If there is a way to group like 'edible', 'inedible', I can get or do any changes to the particular group so that all group member instances will be affected.

jbaums
  • 27,115
  • 5
  • 79
  • 119
Débora
  • 5,816
  • 28
  • 99
  • 171
  • Can you please clarify how you want to access the single objects within your group? Why isn't it just Cache>? With the string key being your group id. – cruftex Mar 11 '14 at 18:05
  • @cruftex : Thanks for reply and you may read my edit please. – Débora Mar 11 '14 at 18:47
  • I still don't get it. How do you address the groups or part of the groups? What is you access pattern? – cruftex Mar 12 '14 at 08:40
  • @cruftex. I re edited with an practical example. Will you take a look please. It is not clear what u meant by 'access pattern' . – Débora Mar 12 '14 at 16:47
  • With "access pattern" I mean what is the key to your objects and what operations are you doing on them, e.g. "mostly adding an object at the end of a group" or just doing point requests by the product id. – cruftex Mar 12 '14 at 17:29
  • Couchbase is a database and a cache, check it out – tgkprog Jul 25 '21 at 20:17

1 Answers1

2

For the moment I cannot see that your usage scenario justifies a special cache feature.

  1. If you update your products in a write through configuration via Cache.put(), the cache is automatically in sync.

  2. If you use a persistence layer e.g. JPA, its internal cache is in sync also.

  3. If you are in charge of controlling the cache yourself, you just need to know what objects belong to a group and do the invalidation, e.g.:

    Cache<Integer,Set<Integer>> groupId2productsId = ....
    Cache<Integer, Product> productId2product = ....
    
    void invalidateGroup(int id) {
      productId2product.removeAll(groupId2productsId.get(id));
    }
    
  4. You can, of course, partition your products into multiple caches (or regions). Then I would do a partition algorithm on top of a normal cache. But this is an unflexible approach, if you have more then one partition criteria or you have overlaps, then you are in trouble.

General note: For addressing a group of objects by a criteria you need an index structure, or iterate through everything. Typically this is the job of a database. EHCache has a search feature build in, so you can query objects within your cache and invalidate them, but I doubt that EHCache has a fast/indexed implementation. I will think about whether it makes sense to put something like this in a cache, however it won't be a "standards" based solution.

cruftex
  • 5,545
  • 2
  • 20
  • 36