1
2
3
4
5
6
7 package org.huihoo.jfox.soaf.services.cache;
8
9 import java.util.Properties;
10
11 import org.huihoo.jfox.soaf.exception.CacheServiceException;
12 import org.huihoo.jfox.soaf.util.resource.PropertiesHelper;
13 import org.huihoo.jfox.soaf.util.resource.StringHelper;
14
15 import com.opensymphony.oscache.base.CacheEntry;
16 import com.opensymphony.oscache.base.Config;
17
18 /***
19 * <p>
20 * OSCacheService for pluggable cache.
21 * </p>
22 *
23 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
24 * @author <a href="mailto:m.bogaert@intrasoft.be">Mathias Bogaert </a>
25 * @version $Revision: 1.1 $ $Date: 2005/05/22 06:48:52 $
26 * @version Revision: 1.0
27 */
28
29 public class OSCacheServiceProvider implements CacheServiceProvider {
30
31 /***
32 * The OSCache refresh period property suffix.
33 */
34 public static final String OSCACHE_REFRESH_PERIOD = "refresh.period";
35
36 /***
37 * The OSCache CRON expression property suffix.
38 */
39 public static final String OSCACHE_CRON = "cron";
40
41 /***
42 * The OSCache cache capacity property suffix.
43 */
44 public static final String OSCACHE_CAPACITY = "capacity";
45
46 private static final Properties OSCACHE_PROPERTIES = new Config()
47 .getProperties();
48
49 /***
50 * @see org.huihoo.jfox.soaf.services.cache.CacheServiceProvider#buildCache(java.lang.String,
51 * java.util.Properties)
52 */
53 public CacheService buildCacheService(String regionName,
54 Properties properties) throws CacheServiceException {
55 int refreshPeriod = PropertiesHelper.getInt(StringHelper.qualify(
56 regionName, OSCACHE_REFRESH_PERIOD), OSCACHE_PROPERTIES,
57 CacheEntry.INDEFINITE_EXPIRY);
58 String cron = OSCACHE_PROPERTIES.getProperty(StringHelper.qualify(
59 regionName, OSCACHE_CRON));
60
61
62 OSCacheServiceImpl cache = new OSCacheServiceImpl(refreshPeriod, cron);
63
64 Integer capacity = PropertiesHelper.getInteger(StringHelper.qualify(
65 regionName, OSCACHE_CAPACITY), OSCACHE_PROPERTIES);
66 if (capacity != null)
67 cache.setCacheCapacity(capacity.intValue());
68
69 return cache;
70 }
71
72 }