如何在 EntityManager (JPA) L1 或 L2 缓存大小中设置限制

发布于 2024-09-28 22:17:40 字数 87 浏览 1 评论 0原文

如何设置 L1 或 L2 缓存大小限制。我担心增加缓存大小。 一种方法是定义缓存超时,但我想知道是否可以对缓存大小进行限制?

RGDS 纳维德

How to set L1 or L2 cache size-limitation. I concern of increasing the cache-size.
One way is defining timeout for cache but i want to know is it possible to make a constraint for cache size or not?

RGDS
Navid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-10-05 22:17:40

如何设置一级缓存大小限制

您不能。唯一的选择是 clear如果您想“控制”,请定期手动持久化上下文(实际上,clear 非常激进,它会删除所有实体)其大小。

如何设置二级缓存大小限制

这取决于底层缓存提供程序。换句话说,这是通过配置 L2 缓存实现来完成的。例如,EHCache 有一个 maxElementInMemory 参数。


L1 发生了什么?!随着时间的推移,内存中会有多少实体?没有任何限制?!

无论您输入多少,直到最终 OutOfMemoryError,因此需要明确地清除

  • 在大型批处理作业上(即使它们发生在单个事务中),
  • 如果长期存在的EntityManager

但通常的模式是使用短期的 EntityManager,并且大多数用例都不是批处理作业,因此这不是问题。

另请参阅

How to set L1 cache size-limitation

You can't. The only option is to clear the persistence context manually at regular intervals if you want to "control" (actually, clear is very aggressive, it removes all entities) its size.

How to set L2 cache size-limitation

This depends on the underlying cache provider. In other words, this is done by configuring the L2 cache implementation. For example, EHCache has a maxElementInMemory parameter.


what happens in L1?! how much entities will be in the memory as time pass? w/o any constrains ?!

As much as you put in it, until an eventual OutOfMemoryError, hence the need to clear explicitly:

  • on large batch jobs (even if they occur in a single transaction)
  • if a long-lived EntityManager is used

But the usual pattern is to use a short-lived EntityManager and most use cases are not batch jobs so this is not a concern.

See also

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文