You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/03/03 22:44:06 UTC

svn commit: r382938 - /incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java

Author: agilliland
Date: Fri Mar  3 13:44:03 2006
New Revision: 382938

URL: http://svn.apache.org/viewcvs?rev=382938&view=rev
Log:
changing last expired date to use a real Cache rather than just a hashtable.  in truth, i think a better long term solution will be to add a lastModified field to the WebsiteData object and just use that.


Modified:
    incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java

Modified: incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java?rev=382938&r1=382937&r2=382938&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java Fri Mar  3 13:44:03 2006
@@ -55,7 +55,7 @@
     private static CacheFactory mCacheFactory = null;
     
     // maintain a cache of the last expired time for each weblog
-    private static Hashtable lastExpiredCache = null;
+    private static Cache lastExpiredCache = null;
     
     // a list of all cache handlers who have obtained a cache
     private static Set cacheHandlers = new HashSet();
@@ -91,8 +91,18 @@
         mLogger.info("Cache Manager Initialized.");
         mLogger.info("Default cache factory = "+mCacheFactory.getClass().getName());
         
+        
         // setup our cache for expiration dates
-        lastExpiredCache = new Hashtable();
+        // TODO: this really should not be something that is cached here
+        //       a better approach would be to add a weblog.lastChanged field
+        //       and track this along with the WebsiteData object
+        String lastExpCacheFactory = RollerConfig.getProperty("cache.lastExpired.factory");
+        Map lastExpProps = new HashMap();
+        if(lastExpCacheFactory != null) {
+            lastExpProps.put("factory", lastExpCacheFactory);
+        }
+        lastExpiredCache = CacheManager.constructCache(null, lastExpProps);
+        
         
         // add custom handlers
         String customHandlers = RollerConfig.getProperty("cache.customHandlers");
@@ -199,7 +209,9 @@
         }
         
         // register the handler for this new cache
-        cacheHandlers.add(handler);
+        if(handler != null) {
+            cacheHandlers.add(handler);
+        }
         
         return cache;
     }
@@ -220,7 +232,9 @@
         
         mLogger.debug("Registering handler "+handler);
         
-        cacheHandlers.add(handler);
+        if(handler != null) {
+            cacheHandlers.add(handler);
+        }
     }
     
     
@@ -228,7 +242,7 @@
         
         mLogger.debug("invalidating entry = "+entry.getAnchor());
         
-        lastExpiredCache.put(entry.getWebsite().getHandle(), new Date());
+        setLastExpiredDate(entry.getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -241,7 +255,7 @@
         
         mLogger.debug("invalidating website = "+website.getHandle());
         
-        lastExpiredCache.put(website.getHandle(), new Date());
+        setLastExpiredDate(website.getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -254,7 +268,7 @@
         
         mLogger.debug("invalidating bookmark = "+bookmark.getId());
         
-        lastExpiredCache.put(bookmark.getWebsite().getHandle(), new Date());
+        setLastExpiredDate(bookmark.getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -267,7 +281,7 @@
         
         mLogger.debug("invalidating folder = "+folder.getId());
         
-        lastExpiredCache.put(folder.getWebsite().getHandle(), new Date());
+        setLastExpiredDate(folder.getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -280,7 +294,7 @@
         
         mLogger.debug("invalidating comment = "+comment.getId());
         
-        lastExpiredCache.put(comment.getWeblogEntry().getWebsite().getHandle(), new Date());
+        setLastExpiredDate(comment.getWeblogEntry().getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -319,7 +333,7 @@
         
         mLogger.debug("invalidating category = "+category.getId());
         
-        lastExpiredCache.put(category.getWebsite().getHandle(), new Date());
+        setLastExpiredDate(category.getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -332,7 +346,7 @@
         
         mLogger.debug("invalidating template = "+template.getId());
         
-        lastExpiredCache.put(template.getWebsite().getHandle(), new Date());
+        setLastExpiredDate(template.getWebsite().getHandle());
         
         Iterator handlers = cacheHandlers.iterator();
         while(handlers.hasNext()) {
@@ -347,12 +361,7 @@
     public static void clear() {
         
         // update all expired dates
-        Iterator it = lastExpiredCache.keySet().iterator();
-        String key = null;
-        while(it.hasNext()) {
-            key = (String) it.next();
-            lastExpiredCache.put(key, new Date());
-        }
+        lastExpiredCache.clear();
         
         // loop through all handlers and trigger a clear
         CacheHandler handler = null;
@@ -371,12 +380,7 @@
     public static void clear(String handlerClass) {
         
         // update all expired dates
-        Iterator it = lastExpiredCache.keySet().iterator();
-        String key = null;
-        while(it.hasNext()) {
-            key = (String) it.next();
-            lastExpiredCache.put(key, new Date());
-        }
+        lastExpiredCache.clear();
         
         // loop through all handlers to find the one we want
         CacheHandler handler = null;
@@ -388,6 +392,11 @@
                 handler.clear();
             }
         }
+    }
+    
+    
+    public static void setLastExpiredDate(String weblogHandle) {
+        lastExpiredCache.put("lastExpired:"+weblogHandle, new Date());
     }
     
     



Re: svn commit: r382938 - /incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java

Posted by Allen Gilliland <Al...@Sun.COM>.
On Fri, 2006-03-03 at 14:02, David M Johnson wrote:
> On Mar 3, 2006, at 4:44 PM, agilliland@apache.org wrote:
> 
> > Author: agilliland
> > Date: Fri Mar  3 13:44:03 2006
> > New Revision: 382938
> >
> > URL: http://svn.apache.org/viewcvs?rev=382938&view=rev
> > Log:
> > changing last expired date to use a real Cache rather than just a  
> > hashtable.  in truth, i think a better long term solution will be  
> > to add a lastModified field to the WebsiteData object and just use  
> > that.
> 
> Yes, we've discussed that one before on the list. It's a better  
> solution.

Cool.  I think that's a pretty easy thing to add, so I have that on my TODO list for this month.

-- Allen


> 
> - Dave
> 


Re: svn commit: r382938 - /incubator/roller/trunk/src/org/roller/presentation/cache/CacheManager.java

Posted by David M Johnson <Da...@Sun.COM>.
On Mar 3, 2006, at 4:44 PM, agilliland@apache.org wrote:

> Author: agilliland
> Date: Fri Mar  3 13:44:03 2006
> New Revision: 382938
>
> URL: http://svn.apache.org/viewcvs?rev=382938&view=rev
> Log:
> changing last expired date to use a real Cache rather than just a  
> hashtable.  in truth, i think a better long term solution will be  
> to add a lastModified field to the WebsiteData object and just use  
> that.

Yes, we've discussed that one before on the list. It's a better  
solution.

- Dave