Skip to content

Instantly share code, notes, and snippets.

@franzwong
Last active August 29, 2015 14:16
Show Gist options
  • Save franzwong/c7863005cf2749382c1d to your computer and use it in GitHub Desktop.
Save franzwong/c7863005cf2749382c1d to your computer and use it in GitHub Desktop.
Ehcache quickstart
package com.franzwong.codepiece.java.ehcache;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class MainApplication {
public static void main(String[] args) {
CacheManager manager = CacheManager.create();
manager.addCache("myCache");
Cache myCache = manager.getCache("myCache");
Element element1 = new Element("id-001", "Franz Wong");
myCache.put(element1);
Element cachedElement1 = myCache.get("id-001");
String value = (String) cachedElement1.getObjectValue();
System.out.println(value);
manager.shutdown();
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.franzwong.java.codepiece.ehcache</groupId>
<artifactId>ehcache001</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment