• Bug
  • Status: Closed
  • 1 Critical
  • Resolution: Fixed
  • ehcache-core
  • hsingh
  • Reporter: cdennis
  • January 22, 2010
  • 0
  • Watchers: 1
  • January 17, 2013
  • February 04, 2010


This story is long and complex, I shall start from the beginning:

In ehcache.xsd the maxElementsInMemory attribute is defined as:

In principle this means that it is illegal to not define a value for this attribute for a given cache (same for defaultCache). In reality the SAXParser used to parse the ehcache.xml files is not schema validating, and so it does not enforce this constraint. Since the attribute has no default value set in the schema this means the bean handler never calls the setMaxElementsInMemory method, and the maxElementsInMemory variable in the CacheConfiguration object stays uninitialized and hence zero.

Compounding this problem is the fact that the zero value for maxElementsInMemory means different things to the different Store implementations. The MemoryStore interprets the zero value as meaning a MemoryStore with zero capacity, whereas the clustered store interprets this to mean a ClusteredStore with an infinite local capacity - i.e. the store will never flush values from the L1 (although the MemoryManager will still do so if the L1 comes under memory pressure). These differences are made stranger by the fact that there is a warning:

“Cache: foo.bar has a maxElementsInMemory of 0. It is strongly recommended to have a maximumSize of at least 1. Performance is halved by not using a MemoryStore.”

printed by the Cache when using a maxElementsInMemory of 0. This is wrong in two ways:

  1. A default configuration value (intended or not) should not lead to warnings about poor configuration.
  2. This warning is obviously wrong in the case of a ClusteredStore - since the 0 indicates and infinite in-memory capacity.


Steve Harris 2010-01-22

What does ehcache use for infinite? Can we just make ours work the same as ehcache mem core

Chris Dennis 2010-01-22

Ehcache does not have a concept of infinite, you simply have to set the max to some very high number.

To me there are two problems to fix here:

Firstly define consistent mappings for MemoryStore and ClusteredStore for 0, finite, and infinite. It seems that there are two choices available: 1: 0->infinite, +ve->finite (this obviously has no way of representing a zero capacity store) 2: -1->infinite, 0->0, +ve->finite

Secondly we have to choose to either make Ehcache validate config files against the schema thus enforcing the required-ness of the maxElementsInMemory attribute or we have to define a more sensible default for maxElementsInMemory, the obvious candidate being infinity (or Integer.MAX_VALUE) depending on the decision on the previous question.

Chris Dennis 2010-02-04

0 now maps to infinity uniformly across all stores: Memory, Disk and Clustered.

Himadri Singh 2010-02-22


Version 1.7.2: 2010-02-22 19:04:58,843 WARN main [net.sf.ehcache.Cache] - Cache: cache has a maxElementsInMemory of 0. It is strongly recommended to have a maximumSize of at least 1. Performance is halved by not using a MemoryStore.

Version 2.0.0-SNAPSHOT (1888) 2010-02-22 19:05:23,703 WARN main [net.sf.ehcache.Cache] - Cache: cache has a maxElementsInMemory of 0. In Ehcache 2.0 this has been changed to mean a store with no capacity limit.