ehcache备忘

-------ehcache.xml---放在classpath下------
<?xml version="1.0" encoding="UTF-8"?> 
<ehcache>
 <diskStore path="java.io.tmpdir" />
 
 <defaultCache 
  maxElementsInMemory="10000" 
  eternal="false" 
  timeToIdleSeconds="1200" 
  timeToLiveSeconds="1200" 
  overflowToDisk="true" 
  diskPersistent="false"/>
  
 <cache name="domain.User" 
  maxElementsInMemory="300" 
  eternal="false" 
  timeToIdleSeconds="300" 
  timeToLiveSeconds="600" 
  overflowToDisk="true" />
</ehcache>


如果用了maven,可以加上
<!-- pom.xml -->
 <dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache-core</artifactId>
 </dependency>


------------java----------------------

public static void main(String[] args) {
  CacheManager manager = CacheManager.create(); 
  Cache cache = manager.getCache("domain.User"); 
  System.out.println(cache.getName());
  
  Element element = new Element("key1", "value22"); 
  cache.put(element); 
  Element element2 = new Element("key1", "value233"); 
  cache.put(element2);
  
  Element e = cache.get("key1"); 
  System.out.println(e.getValue());
  
  manager.shutdown(); 
 }

你可能感兴趣的:(java,maven,xml,.net,cache)