KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > shiftone > cache > util > AbstractPolicyCacheFactory


1 package org.shiftone.cache.util;
2
3
4
5 import org.shiftone.cache.Cache;
6 import org.shiftone.cache.CacheFactory;
7 import org.shiftone.cache.decorator.sync.SyncCache;
8 import org.shiftone.cache.util.reaper.CacheReaper;
9 import org.shiftone.cache.util.reaper.ReapableCache;
10
11
12 /**
13  * @version $Revision: 1.1 $
14  * @author $Author: jeffdrost $
15  */

16 public abstract class AbstractPolicyCacheFactory implements CacheFactory
17 {
18
19     private static final Log LOG = new Log(AbstractPolicyCacheFactory.class);
20     private int period = 1000;
21
22     public abstract ReapableCache newReapableCache(String JavaDoc cacheName, long timeoutMilliSeconds, int maxSize);
23
24
25     public Cache newInstance(String JavaDoc cacheName, long timeoutMilliSeconds, int maxSize)
26     {
27
28         return CacheReaper.register( //
29
new SyncCache( //
30
newReapableCache(cacheName, timeoutMilliSeconds, maxSize)), //
31
period);
32     }
33
34
35     /**
36      * time in milliseconds between calls from the reaper. Every "period"
37      * milliseconds this factory's reaper will wake up and call
38      * "removeExpiredElements" on the cache. Note that changing this value will
39      * only effect new caches - all existing caches will continue with the same
40      * period.
41      */

42     public int getPeriod()
43     {
44         return period;
45     }
46
47
48     public void setPeriod(int period)
49     {
50         this.period = period;
51     }
52 }
53
Popular Tags