简体   繁体   English

缓存区域和缓存内存组:Memcache,EhCache,JCS

[英]Cache Regions and Cache memory Groups: Memcache, EhCache, JCS

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. 我搜索了一些缓存服务,发现JCS支持这一点。 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. 编辑: @ cruftex:假设小商店的库存系统。 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. 如果有一种方法可以将“可食用”,“不可食用”分组,我可以对特定组进行或进行任何更改,以便所有组成员实例都会受到影响。

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. 如果通过Cache.put()以直写配置更新产品,则缓存将自动同步。

  2. If you use a persistence layer eg JPA, its internal cache is in sync also. 如果使用持久层(例如JPA),其内部缓存也是同步的。

  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, eg: 如果您自己负责控制缓存,您只需要知道哪些对象属于一个组并执行失效,例如:

     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. EHCache内置了搜索功能,因此您可以查询缓存中的对象并使其无效,但我怀疑EHCache是​​否具有快速/索引实现。 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. 我会考虑将这样的东西放在缓存中是否有意义,但它不是一个基于“标准”的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM