简体   繁体   English

ehcache 是否尊重 serialVersionUID?

[英]Does ehcache respect serialVersionUID?

We're running ehcache 1.5 in a cluster with RMI replication and update servers one by one (think of a load balancer/proxy on top and zero-downtime updates).我们在具有 RMI 复制和更新服务器的集群中运行 ehcache 1.5(想想顶部的负载平衡器/代理和零停机更新)。

We generally don't care about serialVersionUID .我们通常不关心serialVersionUID Trouble is, very bad things (up to an outage) can happen if you have two versions of an entity in the replicated cache.麻烦的是,如果您在复制缓存中有两个版本的实体,则可能会发生非常糟糕的事情(直至中断)。 That is, if one of the servers running old code replicates an element to the new server where its class has been changed.也就是说,如果其中一台运行旧代码的服务器将元素复制到其 class 已更改的新服务器。

We typically work this around by starting new cluster for updated servers on different port, but it is quite ugly and fragile.我们通常通过为不同端口上的更新服务器启动新集群来解决这个问题,但它非常丑陋和脆弱。

So, the question is: Does clustered, replicated ehcache respect serialVersionUID properly?所以,问题是:集群复制的ehcache是否正确尊重serialVersionUID That is, does it not try and replicate entities if version of the local class is different?也就是说,如果本地 class 的版本不同,它是否不会尝试复制实体?

Thanks for the intuitive guesses, but I'm looking for as hard data as possible, official docs preferred.感谢您的直观猜测,但我正在寻找尽可能硬的数据,首选官方文档。

Ehcache does not support serialVersionUID in the way you're suggesting. Ehcache 不支持您建议的serialVersionUID。 I have experienced the scenario you've described above first hand while running Ehcache both standalone and distributed via Terracotta where an exception will be thrown on the client if the version UIDs, do not match.我在运行 Ehcache 独立运行和通过 Terracotta 分布式运行时亲身体验了您在上面描述的场景,如果版本 UID 不匹配,则会在客户端上引发异常。

Ideally (and I assume this is what you're looking for) objects not matching the serialVersionUID simply would miss the cache, but unfortunately this isn't supported.理想情况下(我假设这是您正在寻找的)与 serialVersionUID 不匹配的对象只会错过缓存,但不幸的是,这不受支持。

If you're looking for a slightly more graceful solution to this problem try changing the cache region name when you change your cached entity, perhaps linking it with the serialVersionUID.如果您正在寻找更优雅的解决方案来解决此问题,请尝试在更改缓存实体时更改缓存区域名称,也许将其与 serialVersionUID 链接。 You'll need to update your ehcache config file to add the new cache region, however it will force resources to only request entities from caches containing the version they support.您需要更新 ehcache 配置文件以添加新的缓存区域,但它会强制资源仅从包含它们支持的版本的缓存中请求实体。 This is a big help in distributed environments where you can't update all resources with the new versions simultaneously and don't want to expire the cache.这在您无法同时使用新版本更新所有资源并且不想使缓存过期的分布式环境中提供了很大帮助。

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

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