KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cache > OSCacheProvider


1 //$Id: OSCacheProvider.java,v 1.6 2005/02/12 07:19:08 steveebersole Exp $
2
package org.hibernate.cache;
3
4 import java.util.Properties JavaDoc;
5
6 import org.hibernate.util.PropertiesHelper;
7 import org.hibernate.util.StringHelper;
8
9 import com.opensymphony.oscache.base.CacheEntry;
10 import com.opensymphony.oscache.base.Config;
11
12 /**
13  * Support for OpenSymphony OSCache. This implementation assumes
14  * that identifiers have well-behaved <tt>toString()</tt> methods.
15  *
16  * @author <a HREF="mailto:m.bogaert@intrasoft.be">Mathias Bogaert</a>
17  */

18 public class OSCacheProvider implements CacheProvider {
19
20     /**
21      * The <tt>OSCache</tt> refresh period property suffix.
22      */

23     public static final String JavaDoc OSCACHE_REFRESH_PERIOD = "refresh.period";
24     /**
25      * The <tt>OSCache</tt> CRON expression property suffix.
26      */

27     public static final String JavaDoc OSCACHE_CRON = "cron";
28     /**
29      * The <tt>OSCache</tt> cache capacity property suffix.
30      */

31     public static final String JavaDoc OSCACHE_CAPACITY = "capacity";
32
33     private static final Properties JavaDoc OSCACHE_PROPERTIES = new Config().getProperties();
34
35     /**
36      * Builds a new {@link Cache} instance, and gets it's properties from the OSCache {@link Config}
37      * which reads the properties file (<code>oscache.properties</code>) from the classpath.
38      * If the file cannot be found or loaded, an the defaults are used.
39      *
40      * @param region
41      * @param properties
42      * @return
43      * @throws CacheException
44      */

45     public Cache buildCache(String JavaDoc region, Properties JavaDoc properties) throws CacheException {
46
47         int refreshPeriod = PropertiesHelper.getInt(
48             StringHelper.qualify(region, OSCACHE_REFRESH_PERIOD),
49             OSCACHE_PROPERTIES,
50             CacheEntry.INDEFINITE_EXPIRY
51         );
52         String JavaDoc cron = OSCACHE_PROPERTIES.getProperty( StringHelper.qualify(region, OSCACHE_CRON) );
53
54         // construct the cache
55
final OSCache cache = new OSCache(refreshPeriod, cron, region);
56
57         Integer JavaDoc capacity = PropertiesHelper.getInteger( StringHelper.qualify(region, OSCACHE_CAPACITY), OSCACHE_PROPERTIES );
58         if ( capacity!=null ) cache.setCacheCapacity( capacity.intValue() );
59
60         return cache;
61     }
62
63     public long nextTimestamp() {
64         return Timestamper.next();
65     }
66
67     /**
68      * Callback to perform any necessary initialization of the underlying cache implementation
69      * during SessionFactory construction.
70      *
71      * @param properties current configuration settings.
72      */

73     public void start(Properties JavaDoc properties) throws CacheException {
74     }
75
76     /**
77      * Callback to perform any necessary cleanup of the underlying cache implementation
78      * during SessionFactory.close().
79      */

80     public void stop() {
81     }
82
83     public boolean isMinimalPutsEnabledByDefault() {
84         return false;
85     }
86
87 }
88
Popular Tags