1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.esigate.cache;
16
17 import java.util.Properties;
18
19 import net.sf.ehcache.CacheManager;
20 import net.sf.ehcache.Ehcache;
21
22 import org.apache.http.impl.client.cache.CacheConfig;
23 import org.apache.http.impl.client.cache.ehcache.EhcacheHttpCacheStorage;
24 import org.esigate.Parameters;
25
26 public class EhcacheCacheStorage extends CacheStorage {
27 public static final String DEFAULT_CACHE_NAME = "EsiGate";
28
29 @Override
30 public void init(Properties properties) {
31 String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValue(properties);
32 String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValue(properties);
33
34 CacheManager cacheManager = CacheManager.create(configurationFileName);
35 Ehcache ehcache = cacheManager.getEhcache(cacheName);
36 if (ehcache == null) {
37 cacheManager.addCache(cacheName);
38 ehcache = cacheManager.getEhcache(cacheName);
39 }
40 CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties);
41 setImpl(new EhcacheHttpCacheStorage(ehcache, cacheConfig));
42 }
43
44 }