Add a dependency to the DirectMemory cache artifact:
<dependency> <groupId>org.apache.directmemory</groupId> <artifactId>directmemory-cache</artifactId> <version>0.2</version> </dependency>
Create your CacheService instance:
CacheService<Object, Object> cacheService = new DirectMemory<Object, Object>() .setNumberOfBuffers( 10 ) .setSize( 1000 ) .setInitialCapacity( 100000 ) .setConcurrencyLevel( 4 ) .newCacheService();
Use the cache service to store object, Those methods returns a Pointer if this pointer is null your object has not been stored:
put( K key, V value ) put( K key, V value, int expiresIn )
Retrieve an Object from the cache service:
V retrieve( K key );
Clear at the end of usage and close the CacheService
cacheService.clear(); cacheService.close(); // close() is available in 0.2+ only