blob: b99faf70237f5f48066146498a15d85e9eccaa96 [file] [log] [blame]
------
Apache DirectMemory EHCache Integration
------
Olivier Lamy
------
2012-06-17
------
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
~~ NOTE: For help with the syntax of this file, see:
~~ http://maven.apache.org/doxia/references/apt-format.html
EHCache Integration
You can mix the use of the ehcache framework with DirectMemory. Recent versions of ehcache have some features to store elements
in a heap off storage when overflow a number of objects or bytes in heap cache.
First you need to declare dependency to the DirectMemory ehcache integration:
+------------------------
<dependency>
<groupId>org.apache.directmemory</groupId>
<artifactId>directmemory-ehcache</artifactId>
<version>${currentRelease}</version>
</dependency>
+------------------------
Note the heap off cache class to use is not currently configurable in ehcahce see issue {{{https://jira.terracotta.org/jira/browse/EHC-940}https://jira.terracotta.org/jira/browse/EHC-940}}.
So Apache DirectMemory contains same package/class name as needed by ehcache.
Activate the feature in ehcache:
+------------------------
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName( "foo" );
cacheConfiguration.setOverflowToOffHeap( true );
cacheConfiguration.setMaxBytesLocalHeap( Long.valueOf( 100 * 1024 * 1024 ) );
cacheConfiguration.setMaxBytesLocalOffHeap( Long.valueOf( 100 * 1024 * 1024 ) );
Cache cache = new Cache( cacheConfiguration );
CacheManager.getInstance().addCache( cache );
+------------------------