gpt4 book ai didi

ehcache - spring ehcache 与自填充缓存范围的集成

转载 作者:行者123 更新时间:2023-12-04 20:48:08 30 4
gpt4 key购买 nike

我必须集成 spring 和 ehcache,并尝试使用 来实现它阻塞缓存 图案

<ehcache:annotation-driven/>

有一个选项自填充缓存范围 对于 共享(默认)和方法 .你能解释一下有什么区别吗?

还有注解 @可缓存自我填充 旗帜

根据我在一些帖子上读到的

http://groups.google.com/group/ehcache-spring-annotations/browse_thread/thread/7dbc71ce34f6ee19/b057610167dfb815?lnk=raot

它说当 共享 使用 仅创建一个实例 并且每次使用相同的缓存名称时都会使用相同的名称,所以如果我使用 自我填充 将一种方法标记为真,

all the threads trying to access other methods annotated with @Cacheable with selfPopulating flag set to true will go on hold which I dont want


<ehcache:annotation-driven/>

自填充缓存范围 = 方法 另一方面创建 单独的实例 对于使用 @Cacheable 注释的所有方法,selfPopulating 标志设置为 true,因此不会产生问题。

但在这种情况下,当我尝试使用 删除元素时@TriggerRemove 并给出@Cacheable 中使用的缓存名称,它会在每个单独的实例中搜索以找到值吗?这不是开销吗?

最佳答案

由 Eric 在上面的 ehcache google 组中回答

In all cases there is one underlying Ehcache instance. What happens when you set selfPopulating=true is a SelfPopulatingCache wrapper is created.

If cache-scope=shared then all annotations using that named cache will use the same SelfPopulatingCache wrapper If cache-scope=method then one wrapper is created per method

Note in both cases the SelfPopulatingCache is a wrapper, there is still only one actual cache backing the wrapper(s)

As for blocking, If you read the docs for SelfPopulatingCache and BlockingCache you'll notice that ehcache does a compromise between cache level locking and per-key locking via key striping. http://ehcache.org/apidocs/net/sf/ehcache/constructs/blocking/BlockingCache.html

关于ehcache - spring ehcache 与自填充缓存范围的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10122267/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com