portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r345127 - in /portals/jetspeed-2/trunk/components/page-manager/src: java/org/apache/jetspeed/page/impl/ test/
Date Wed, 16 Nov 2005 21:15:43 GMT
Author: rwatler
Date: Wed Nov 16 13:15:25 2005
New Revision: 345127

URL: http://svn.apache.org/viewcvs?rev=345127&view=rev
Log:
add expiring cache to DB PageManager, default expiration = 150 sec.

Modified:
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
    portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
    portals/jetspeed-2/trunk/components/page-manager/src/test/database-page-manager.xml
    portals/jetspeed-2/trunk/components/page-manager/src/test/secure-database-page-manager.xml

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=345127&r1=345126&r2=345127&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
Wed Nov 16 13:15:25 2005
@@ -77,6 +77,8 @@
 public class DatabasePageManager extends InitablePersistenceBrokerDaoSupport implements PageManager
 {
     private static final int DEFAULT_CACHE_SIZE = 128;
+    private static final int MIN_CACHE_EXPIRES_SECONDS = 30;
+    private static final int DEFAULT_CACHE_EXPIRES_SECONDS = 150;
 
     private static Map modelClasses = new HashMap();
     static
@@ -100,13 +102,27 @@
     
     private int cacheSize;
 
+    private int cacheExpiresSeconds;
+
     private DatabasePageManagerCache cache;
 
-    public DatabasePageManager(String repositoryPath, int cacheSize, boolean isPermissionsSecurity,
boolean isConstraintsSecurity)
+    public DatabasePageManager(String repositoryPath, int cacheSize, int cacheExpiresSeconds,
boolean isPermissionsSecurity, boolean isConstraintsSecurity)
     {
         super(repositoryPath);
         delegator = new DelegatingPageManager(isPermissionsSecurity, isConstraintsSecurity,
modelClasses);
         this.cacheSize = Math.max(cacheSize, DEFAULT_CACHE_SIZE);
+        if (cacheExpiresSeconds < 0)
+        {
+            this.cacheExpiresSeconds = DEFAULT_CACHE_EXPIRES_SECONDS;
+        }
+        else if (cacheExpiresSeconds == 0)
+        {
+            this.cacheExpiresSeconds = 0;
+        }
+        else
+        {
+            this.cacheExpiresSeconds = Math.max(cacheExpiresSeconds, MIN_CACHE_EXPIRES_SECONDS);
+        }
         DatabasePageManagerCache.cacheInit(this);
     }
 
@@ -118,6 +134,16 @@
     public int getCacheSize()
     {
         return cacheSize;
+    }
+
+    /**
+     * getCacheExpiresSeconds
+     *
+     * @return configured cache expiration in seconds
+     */
+    public int getCacheExpiresSeconds()
+    {
+        return cacheExpiresSeconds;
     }
 
     /* (non-Javadoc)

Modified: portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java?rev=345127&r1=345126&r2=345127&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/java/org/apache/jetspeed/page/impl/DatabasePageManagerCache.java
Wed Nov 16 13:15:25 2005
@@ -36,6 +36,7 @@
 {
     private static LRUMap cacheByOID;
     private static LRUMap cacheByPath;
+    private static int cacheExpiresSeconds;
     private static boolean constraintsEnabled;
     private static boolean permissionsEnabled;
 
@@ -52,6 +53,7 @@
         {
             cacheByOID = new LRUMap(pageManager.getCacheSize());
             cacheByPath = new LRUMap(pageManager.getCacheSize());
+            cacheExpiresSeconds = pageManager.getCacheExpiresSeconds();
             constraintsEnabled = pageManager.getConstraintsEnabled();
             permissionsEnabled = pageManager.getPermissionsEnabled();
         }
@@ -67,9 +69,7 @@
      */
     public synchronized static NodeImpl cacheLookup(String path)
     {
-        Identity oid = (Identity)cacheByPath.get(path);
-        NodeImpl node = (NodeImpl)cacheByOID.get(oid);
-        return node;
+        return (NodeImpl)cacheLookup((Identity)cacheByPath.get(path));
     }
 
     /**
@@ -83,7 +83,15 @@
      */
     public synchronized static void cacheAdd(Identity oid, Object obj)
     {
-        cacheByOID.put(oid, obj);
+        Entry entry = (Entry)cacheByOID.get(oid);
+        if (entry != null)
+        {
+            entry.put(obj);
+        }
+        else
+        {
+            cacheByOID.put(oid, new Entry(obj));
+        }
         if (obj instanceof NodeImpl)
         {
             NodeImpl node = (NodeImpl)obj;
@@ -114,7 +122,15 @@
      */
     public synchronized static Object cacheLookup(Identity oid)
     {
-        return cacheByOID.get(oid);
+        if (oid != null)
+        {
+            Entry entry = (Entry)cacheByOID.get(oid);
+            if (entry != null)
+            {
+                return entry.get();
+            }
+        }
+        return null;
     }
 
     /**
@@ -126,11 +142,14 @@
      */
     public synchronized static void cacheRemove(Identity oid)
     {
-        Object obj = cacheByOID.remove(oid);
-        if (obj instanceof NodeImpl)
+        Entry entry = (Entry)cacheByOID.remove(oid);
+        if (entry != null)
         {
-            NodeImpl node = (NodeImpl)obj;
-            cacheByPath.remove(node.getPath());
+            Object obj = entry.get();
+            if (obj instanceof NodeImpl)
+            {
+                cacheByPath.remove(((NodeImpl)obj).getPath());
+            }
         }
     }
 
@@ -145,11 +164,54 @@
         Iterator objectsIter = cacheByOID.values().iterator();
         while (objectsIter.hasNext())
         {
-            Object obj = objectsIter.next();
+            Object obj = ((Entry)objectsIter.next()).get();
             if (obj instanceof NodeImpl)
             {
                 ((NodeImpl)obj).resetCachedSecurityConstraints();
             }
+        }
+    }
+
+    /**
+     * Entry
+     *
+     * Cache entry class adding entry timestamp to track expiration
+     */
+    private static class Entry
+    {
+        public long timestamp;
+        public Object element;
+
+        public Entry(Object element)
+        {
+            put(element);
+            timestamp = System.currentTimeMillis();
+        }
+
+        public Object get()
+        {
+            if ((DatabasePageManagerCache.cacheExpiresSeconds > 0) && (element
!= null))
+            {
+                long now = System.currentTimeMillis();
+                if (((now - timestamp) / 1000) > DatabasePageManagerCache.cacheExpiresSeconds)
+                {
+                    element = null;
+                }
+                else
+                {
+                    timestamp = now;
+                }
+            }
+            return element;
+        }
+        
+        public void put(Object element)
+        {
+            if (DatabasePageManagerCache.cacheExpiresSeconds > 0)
+            {
+                timestamp = System.currentTimeMillis();
+            }
+            this.element = element;
         }
     }
 

Modified: portals/jetspeed-2/trunk/components/page-manager/src/test/database-page-manager.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/test/database-page-manager.xml?rev=345127&r1=345126&r2=345127&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/test/database-page-manager.xml (original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/test/database-page-manager.xml Wed
Nov 16 13:15:25 2005
@@ -24,12 +24,14 @@
           class="org.apache.jetspeed.page.impl.DatabasePageManager">
         <!-- OJB configuration file resource path -->
         <constructor-arg index="0"><value>JETSPEED-INF/ojb/page-manager-repository.xml</value></constructor-arg>
      
-        <!-- folder/page/link cache size -->
+        <!-- folder/page/link cache size, default=128, min=128 -->
         <constructor-arg index="1"><value>128</value></constructor-arg>
-        <!-- permissions security enabled flag -->
-        <constructor-arg index="2"><value>false</value></constructor-arg>
-        <!-- constraints security enabled flag -->
+        <!-- folder/page/link cache expires seconds, default=150, infinite=0, min=30 -->
+        <constructor-arg index="2"><value>0</value></constructor-arg>
+        <!-- permissions security enabled flag, default=false -->
         <constructor-arg index="3"><value>false</value></constructor-arg>
+        <!-- constraints security enabled flag, default=true -->
+        <constructor-arg index="4"><value>false</value></constructor-arg>
     </bean>
 
     <!-- Transaction Proxying -->

Modified: portals/jetspeed-2/trunk/components/page-manager/src/test/secure-database-page-manager.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/page-manager/src/test/secure-database-page-manager.xml?rev=345127&r1=345126&r2=345127&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/page-manager/src/test/secure-database-page-manager.xml
(original)
+++ portals/jetspeed-2/trunk/components/page-manager/src/test/secure-database-page-manager.xml
Wed Nov 16 13:15:25 2005
@@ -24,12 +24,14 @@
           class="org.apache.jetspeed.page.impl.DatabasePageManager">
         <!-- OJB configuration file resource path -->
         <constructor-arg index="0"><value>JETSPEED-INF/ojb/page-manager-repository.xml</value></constructor-arg>
      
-        <!-- folder/page/link cache size -->
+        <!-- folder/page/link cache size, default=128, min=128 -->
         <constructor-arg index="1"><value>128</value></constructor-arg>
-        <!-- permissions security enabled flag -->
-        <constructor-arg index="2"><value>false</value></constructor-arg>
-        <!-- constraints security enabled flag -->
-        <constructor-arg index="3"><value>true</value></constructor-arg>
+        <!-- folder/page/link cache expires seconds, default=150, infinite=0, min=30 -->
+        <constructor-arg index="2"><value>0</value></constructor-arg>
+        <!-- permissions security enabled flag, default=false -->
+        <constructor-arg index="3"><value>false</value></constructor-arg>
+        <!-- constraints security enabled flag, default=true -->
+        <constructor-arg index="4"><value>true</value></constructor-arg>
     </bean>
 
     <!-- Transaction Proxying -->



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message