views:

25

answers:

1

hi

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

+2  A: 

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

Pascal Thivent
what happens in L1?! how much entities will be in the memory as time pass? w/o any constrains ?!
Navid
@Navid See my update
Pascal Thivent
You mean it is not my responsible to clear the L1 or L2 cache. isn't it? and caches will be removed automatically?
Navid
I mean that the L1 cache is per EntityManager which is typically a short-lived object. So unless you're doing batch jobs or unless you're using a long-lived EntityManager, you don't have to worry.
Pascal Thivent