cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r427587 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src: main/java/org/apache/cayenne/cache/OSQueryCache.java test/java/org/apache/cayenne/cache/OSQueryCacheTst.java
Date Tue, 01 Aug 2006 14:22:52 GMT
Author: aadamchik
Date: Tue Aug  1 07:22:51 2006
New Revision: 427587

URL: http://svn.apache.org/viewvc?rev=427587&view=rev
Log:
CAY-613 - exposing OSCache internals to simplify extensions

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/cache/OSQueryCache.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/cache/OSQueryCacheTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/cache/OSQueryCache.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/cache/OSQueryCache.java?rev=427587&r1=427586&r2=427587&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/cache/OSQueryCache.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/cache/OSQueryCache.java
Tue Aug  1 07:22:51 2006
@@ -40,31 +40,31 @@
  * look like this:
  * 
  * <pre>
- *              # OSCache configuration file
- *             
- *              # OSCache standard configuration per
- *              #     http://www.opensymphony.com/oscache/wiki/Configuration.html
- *              # ---------------------------------------------------------------
- *             
- *              #cache.memory=true
- *              cache.capacity=5000
- *              cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
- *             
- *             
- *              # Cayenne specific properties
- *              # ---------------------------------------------------------------
- *             
- *              # Default refresh period in seconds:
- *              cayenne.default.refresh = 60
- *             
- *              # Default expiry specified as cron expressions per
- *              #    http://www.opensymphony.com/oscache/wiki/Cron%20Expressions.html
- *              # expire entries every hour on the 10's minute
- *              cayenne.default.cron = 10 * * * *
- *             
- *              # Same parameters can be overriden per query
- *              cayenne.group.xyz.refresh = 120
- *              cayenne.group.xyz.cron = 10 1 * * *
+ *                # OSCache configuration file
+ *               
+ *                # OSCache standard configuration per
+ *                #     http://www.opensymphony.com/oscache/wiki/Configuration.html
+ *                # ---------------------------------------------------------------
+ *               
+ *                #cache.memory=true
+ *                cache.capacity=5000
+ *                cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
+ *               
+ *               
+ *                # Cayenne specific properties
+ *                # ---------------------------------------------------------------
+ *               
+ *                # Default refresh period in seconds:
+ *                cayenne.default.refresh = 60
+ *               
+ *                # Default expiry specified as cron expressions per
+ *                #    http://www.opensymphony.com/oscache/wiki/Cron%20Expressions.html
+ *                # expire entries every hour on the 10's minute
+ *                cayenne.default.cron = 10 * * * *
+ *               
+ *                # Same parameters can be overriden per query
+ *                cayenne.group.xyz.refresh = 120
+ *                cayenne.group.xyz.cron = 10 1 * * *
  * </pre>
  * 
  * Further extension of OSQueryCache is possible by using OSCache listener API.
@@ -83,7 +83,7 @@
     static String REFRESH_SUFFIX = ".refresh";
     static String CRON_SUFFIX = ".cron";
 
-    protected GeneralCacheAdministrator cache;
+    protected GeneralCacheAdministrator osCache;
 
     RefreshSpecification defaultRefreshSpecification;
     Map refreshSpecifications;
@@ -93,17 +93,20 @@
         init(admin, admin.getProperties());
     }
 
-    public OSQueryCache(Properties properties) {
-        init(new GeneralCacheAdministrator(), properties);
+    public OSQueryCache(GeneralCacheAdministrator cache, Properties properties) {
+        init(cache, properties);
     }
 
-    OSQueryCache(GeneralCacheAdministrator cache, Properties properties) {
-        init(cache, properties);
+    /**
+     * Returns the underlying OSCache manager object.
+     */
+    public GeneralCacheAdministrator getOsCache() {
+        return osCache;
     }
 
     void init(GeneralCacheAdministrator cache, Properties properties) {
 
-        this.cache = cache;
+        this.osCache = cache;
         this.defaultRefreshSpecification = new RefreshSpecification();
 
         // load defaults and per-query settings
@@ -188,13 +191,13 @@
         }
 
         try {
-            return (List) cache.getFromCache(
+            return (List) osCache.getFromCache(
                     key,
                     refresh.refreshPeriod,
                     refresh.cronExpression);
         }
         catch (NeedsRefreshException e) {
-            cache.cancelUpdate(key);
+            osCache.cancelUpdate(key);
             return null;
         }
     }
@@ -202,32 +205,32 @@
     public void put(QueryMetadata metadata, List results) {
         String key = metadata.getCacheKey();
         if (key != null) {
-            cache.putInCache(key, results, metadata.getCacheGroups());
+            osCache.putInCache(key, results, metadata.getCacheGroups());
         }
     }
 
     public void remove(String key) {
         if (key != null) {
-            cache.removeEntry(key);
+            osCache.removeEntry(key);
         }
     }
 
     public void removeGroup(String groupKey) {
         if (groupKey != null) {
-            cache.flushGroup(groupKey);
+            osCache.flushGroup(groupKey);
         }
     }
 
     public void clear() {
-        cache.flushAll();
+        osCache.flushAll();
     }
 
     public int size() {
-        return cache.getCache().getSize();
+        return osCache.getCache().getSize();
     }
 
     public int capacity() {
-        return cache.getCache().getCapacity();
+        return osCache.getCache().getCapacity();
     }
 
     final static class RefreshSpecification {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/cache/OSQueryCacheTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/cache/OSQueryCacheTst.java?rev=427587&r1=427586&r2=427587&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/cache/OSQueryCacheTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/cache/OSQueryCacheTst.java
Tue Aug  1 07:22:51 2006
@@ -29,6 +29,7 @@
 import org.apache.cayenne.query.QueryMetadata;
 
 import com.opensymphony.oscache.base.CacheEntry;
+import com.opensymphony.oscache.general.GeneralCacheAdministrator;
 
 public class OSQueryCacheTst extends TestCase {
 
@@ -47,7 +48,7 @@
         Properties props = new Properties();
         props.put(OSQueryCache.DEFAULT_REFRESH_KEY, "15");
         props.put(OSQueryCache.DEFAULT_CRON_KEY, "9 * * * * *");
-        OSQueryCache cache = new OSQueryCache(props);
+        OSQueryCache cache = new OSQueryCache(new GeneralCacheAdministrator(), props);
 
         assertNull(cache.refreshSpecifications);
         assertEquals("9 * * * * *", cache.defaultRefreshSpecification.cronExpression);
@@ -66,7 +67,7 @@
                 OSQueryCache.GROUP_PREFIX + "XYZ" + OSQueryCache.CRON_SUFFIX,
                 "24 * * * * *");
 
-        OSQueryCache cache = new OSQueryCache(props);
+        OSQueryCache cache = new OSQueryCache(new GeneralCacheAdministrator(), props);
 
         assertNotNull(cache.refreshSpecifications);
         assertEquals(2, cache.refreshSpecifications.size());



Mime
View raw message