I'm experimenting with using Hazelcast as the second-level cache for Hibernate. I'm unsure where to specify the cache configuration. I've added the following to my Hazelcast XML:
<map name="com.blah.entity.*">
<backup-count>1</backup-count>
<time-to-live-seconds>3600</time-to-live-seconds>
<max-idle-seconds>600</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="PER_NODE">5</max-size>
<eviction-percentage>25</eviction-percentage>
<near-cache>
<max-size>5</max-size>
<time-to-live-seconds>3600</time-to-live-seconds>
<max-idle-seconds>600</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<invalidate-on-change>true</invalidate-on-change>
</near-cache>
</map>
However, when I use JVisualVM (with JMX plugin) to view the Map MBean, I see that the size of the map is 21 (which is larger than my max size of 5).
The maps 'config' attribute on the MBean shows that my configuration has been applied:
MapConfig{name='com.blah.entity.*',
inMemoryFormat=BINARY',
backupCount=1,
asyncBackupCount=0,
timeToLiveSeconds=3600,
maxIdleSeconds=600,
evictionPolicy='LRU',
evictionPercentage=25,
maxSizeConfig=MaxSizeConfig{maxSizePolicy='PER_NODE',
size=5},
readBackupData=false,
nearCacheConfig=NearCacheConfig{timeToLiveSeconds=3600,
maxSize=5,
evictionPolicy='LRU',
maxIdleSeconds=600,
invalidateOnChange=true,
inMemoryFormat=BINARY,
cacheLocalEntries=false},
mapStoreConfig=null,
mergePolicyConfig='com.hazelcast.map.merge.PutIfAbsentMapMergePolicy',
wanReplicationRef=null,
listenerConfigs=[],
mapIndexConfigs=[]}
Am I doing something wrong in the config, or am I misreading the JMX data?
EDIT
Just to clear up any confusion, the documentation says the following:
Hazelcast creates a separate distributed map for each Hibernate cache region. So, these regions can be configured easily via Hazelcast map configuration. You can define backup, eviction, TTL and Near Cache properties.
I want to set the max-size property on the maps for the cache regions for my entities because I don't want the cache to expand without limit.