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/07/17 07:31:48 UTC
svn commit: r422627 - in /incubator/roller/branches/roller_3.0:
src/org/apache/roller/ui/rendering/filters/
src/org/apache/roller/ui/rendering/servlets/
src/org/apache/roller/ui/rendering/util/ src/org/apache/roller/util/
src/org/apache/roller/util/cac...
Author: agilliland
Date: Sun Jul 16 22:31:47 2006
New Revision: 422627
URL: http://svn.apache.org/viewvc?rev=422627&view=rev
Log:
some tweaks to cache classes for Roller 3.0
- decoupled the Cache and CacheHandler and bit. both can be registered and used more independently of one another now.
- removed clear() and getStats() methods from CacheHandler interface.
- renamed stats() to getStats() in Cache interface, and now Cache implementations are actually expected to maintain their own stats.
- ripped out extra methods and metrics gathering stuff from page, feed, and planet servlets.
Modified:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/MainPageCacheFilter.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/PlanetCache.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/GenericThrottle.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/Cache.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheFactory.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheHandler.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheManager.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringCacheEntry.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheFactoryImpl.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheImpl.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheFactoryImpl.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheImpl.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LazyExpiringCacheEntry.java
incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/MainPageCacheFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/MainPageCacheFilter.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/MainPageCacheFilter.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/MainPageCacheFilter.java Sun Jul 16 22:31:47 2006
@@ -312,6 +312,7 @@
RollerConfig.getBooleanProperty("cache.mainpage.excludeOwnerEditPages");
Map cacheProps = new HashMap();
+ cacheProps.put("id", CACHE_ID);
Enumeration allProps = RollerConfig.keys();
String prop = null;
while(allProps.hasMoreElements()) {
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java Sun Jul 16 22:31:47 2006
@@ -64,7 +64,7 @@
* @web.servlet name="FeedServlet" load-on-startup="5"
* @web.servlet-mapping url-pattern="/roller-ui/rendering/feed/*"
*/
-public class FeedServlet extends HttpServlet implements CacheHandler {
+public class FeedServlet extends HttpServlet {
private static Log log = LogFactory.getLog(FeedServlet.class);
@@ -74,12 +74,6 @@
private Cache contentCache = null;
- // for metrics
- private double hits = 0;
- private double misses = 0;
- private double purges = 0;
- private Date startTime = new Date();
-
/**
* Init method for this servlet
@@ -91,6 +85,7 @@
log.info("Initializing FeedServlet");
Map cacheProps = new HashMap();
+ cacheProps.put("id", CACHE_ID);
Enumeration allProps = RollerConfig.keys();
String prop = null;
while(allProps.hasMoreElements()) {
@@ -105,7 +100,7 @@
log.info("Feed cache = "+cacheProps);
- contentCache = CacheManager.constructCache(this, cacheProps);
+ contentCache = CacheManager.constructCache(null, cacheProps);
}
@@ -159,7 +154,6 @@
if(cachedContent != null) {
log.debug("HIT "+cacheKey);
- this.hits++;
response.setContentLength(cachedContent.getContent().length);
response.getOutputStream().write(cachedContent.getContent());
@@ -171,7 +165,6 @@
} else {
log.debug("MISS "+cacheKey);
- this.misses++;
}
// set content type
@@ -309,110 +302,6 @@
}
return key.toString();
- }
-
-
- /**
- * A weblog entry has changed.
- */
- public void invalidate(WeblogEntryData entry) {
- // ignored
- }
-
-
- /**
- * A weblog has changed.
- */
- public void invalidate(WebsiteData website) {
- // ignored
- }
-
-
- /**
- * A bookmark has changed.
- */
- public void invalidate(BookmarkData bookmark) {
- // ignored
- }
-
-
- /**
- * A folder has changed.
- */
- public void invalidate(FolderData folder) {
- // ignored
- }
-
-
- /**
- * A comment has changed.
- */
- public void invalidate(CommentData comment) {
- // ignored
- }
-
-
- /**
- * A referer has changed.
- */
- public void invalidate(RefererData referer) {
- // ignored
- }
-
-
- /**
- * A user profile has changed.
- */
- public void invalidate(UserData user) {
- // ignored
- }
-
-
- /**
- * A category has changed.
- */
- public void invalidate(WeblogCategoryData category) {
- // ignored
- }
-
-
- /**
- * Clear the entire cache.
- */
- public void clear() {
- log.info("Clearing cache");
- this.contentCache.clear();
- this.startTime = new Date();
- this.hits = 0;
- this.misses = 0;
- this.purges = 0;
- }
-
-
- /**
- * A weblog template has changed.
- */
- public void invalidate(WeblogTemplate template) {
- // ignored
- }
-
-
- public Map getStats() {
-
- Map stats = new HashMap();
- stats.put("cacheType", this.contentCache.getClass().getName());
- stats.put("startTime", this.startTime);
- stats.put("hits", new Double(this.hits));
- stats.put("misses", new Double(this.misses));
- stats.put("purges", new Double(this.purges));
-
- // calculate efficiency
- if((misses - purges) > 0) {
- double efficiency = hits / (misses + hits);
- stats.put("efficiency", new Double(efficiency * 100));
- }
-
- return stats;
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java Sun Jul 16 22:31:47 2006
@@ -75,13 +75,6 @@
private boolean excludeOwnerPages = false;
private Cache contentCache = null;
- // for metrics
- private double hits = 0;
- private double misses = 0;
- private double purges = 0;
- private double skips = 0;
- private Date startTime = new Date();
-
/**
* Init method for this servlet
@@ -96,6 +89,7 @@
RollerConfig.getBooleanProperty(this.CACHE_ID+".excludeOwnerEditPages");
Map cacheProps = new HashMap();
+ cacheProps.put("id", CACHE_ID);
Enumeration allProps = RollerConfig.keys();
String prop = null;
while(allProps.hasMoreElements()) {
@@ -178,7 +172,6 @@
if(cachedContent != null) {
log.debug("HIT "+cacheKey);
- this.hits++;
response.setContentLength(cachedContent.getContent().length);
response.getOutputStream().write(cachedContent.getContent());
@@ -190,7 +183,6 @@
} else {
log.debug("MISS "+cacheKey);
- this.misses++;
}
}
@@ -356,7 +348,6 @@
this.contentCache.put(cacheKey, new LazyExpiringCacheEntry(rendererOutput));
} else {
log.debug("SKIPPED "+cacheKey);
- this.skips++;
}
log.debug("Exiting");
@@ -506,40 +497,6 @@
* A weblog template has changed.
*/
public void invalidate(WeblogTemplate template) {
- }
-
-
- /**
- * Clear the entire cache.
- */
- public void clear() {
- log.info("Clearing cache");
- this.contentCache.clear();
- this.startTime = new Date();
- this.hits = 0;
- this.misses = 0;
- this.purges = 0;
- this.skips = 0;
- }
-
-
- public Map getStats() {
-
- Map stats = new HashMap();
- stats.put("cacheType", this.contentCache.getClass().getName());
- stats.put("startTime", this.startTime);
- stats.put("hits", new Double(this.hits));
- stats.put("misses", new Double(this.misses));
- stats.put("purges", new Double(this.purges));
- stats.put("skips", new Double(this.skips));
-
- // calculate efficiency
- if((misses - purges) > 0) {
- double efficiency = hits / (misses + hits);
- stats.put("efficiency", new Double(efficiency * 100));
- }
-
- return stats;
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/PlanetCache.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/PlanetCache.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/PlanetCache.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/PlanetCache.java Sun Jul 16 22:31:47 2006
@@ -71,6 +71,7 @@
private PlanetCache() {
Map cacheProps = new HashMap();
+ cacheProps.put("id", CACHE_ID);
Enumeration allProps = RollerConfig.keys();
String prop = null;
while(allProps.hasMoreElements()) {
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/GenericThrottle.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/GenericThrottle.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/GenericThrottle.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/GenericThrottle.java Sun Jul 16 22:31:47 2006
@@ -64,6 +64,7 @@
// cache props
Map cacheProps = new HashMap();
+ cacheProps.put("id", "throttle");
cacheProps.put("size", ""+maxEntries);
cacheProps.put("timeout", ""+this.interval);
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/Cache.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/Cache.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/Cache.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/Cache.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -28,6 +28,12 @@
public interface Cache {
/**
+ * a unique identifier for the cache.
+ */
+ public String getId();
+
+
+ /**
* put an item in the cache.
*/
public void put(String key, Object value);
@@ -46,26 +52,14 @@
/**
- * remove a set of items from the cache.
- */
- public void remove(Set keys);
-
-
- /**
* clear the entire cache.
*/
public void clear();
/**
- * get a list of keys used in the cache.
- */
- public Set keySet();
-
-
- /**
* get cache stats.
*/
- public Map stats();
+ public Map getStats();
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheFactory.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheFactory.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheFactory.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheFactory.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheHandler.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheHandler.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheHandler.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheHandler.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -31,12 +31,13 @@
/**
- * A class which utilizes a cache.
+ * Represents someone that wants to receive notifications about cache
+ * invalidation events.
*
- * The primary purpose of this interface is to force cache handlers to implement
- * the set of invalidate() methods which server as notifications of changed
- * objects. Various caches can determine for themselves how to deal with changes
- * to each type of object.
+ * A CacheHandler can be registered with the CacheManager and then will
+ * receive all the various object invalidation events happening in the
+ * system. Typically classes which are using a cache will want to implement
+ * this interface so that they can know when to remove items from their cache.
*/
public interface CacheHandler {
@@ -57,9 +58,5 @@
public void invalidate(WeblogCategoryData category);
public void invalidate(WeblogTemplate template);
-
- public void clear();
-
- public Map getStats();
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheManager.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheManager.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/CacheManager.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -55,8 +55,6 @@
* changes in the system we often need to notify all caches that some part of
* their cached data needs to be invalidated, and the CacheManager makes that
* process easier.
- *
- * @author Allen Gilliland
*/
public class CacheManager {
@@ -68,9 +66,12 @@
// a reference to the cache factory in use
private static CacheFactory cacheFactory = null;
- // a list of all cache handlers who have obtained a cache
+ // a set of all registered cache handlers
private static Set cacheHandlers = new HashSet();
+ // a map of all registered caches
+ private static Map caches = new HashMap();
+
private static ContinuousWorkerThread futureInvalidationsThread = null;
@@ -97,6 +98,7 @@
cacheFactory = (CacheFactory) factoryClass.newInstance();
} catch(Exception e) {
log.fatal("Failed to instantiate a cache factory", e);
+ throw new RuntimeException(e);
}
log.info("Cache Manager Initialized.");
@@ -207,11 +209,15 @@
cache = cacheFactory.constructCache(properties);
}
- // register the handler for this new cache
- if(handler != null) {
- cacheHandlers.add(handler);
+ if(cache != null) {
+ caches.put(cache.getId(), cache);
+
+ // register the handler for this new cache
+ if(handler != null) {
+ cacheHandlers.add(handler);
+ }
}
-
+
return cache;
}
@@ -345,37 +351,31 @@
*/
public static void clear() {
- // loop through all handlers and trigger a clear
- CacheHandler handler = null;
- Iterator handlers = cacheHandlers.iterator();
- while(handlers.hasNext()) {
- handler = (CacheHandler) handlers.next();
+ // loop through all caches and trigger a clear
+ Cache cache = null;
+ Iterator cachesIT = caches.values().iterator();
+ while(cachesIT.hasNext()) {
+ cache = (Cache) cachesIT.next();
- handler.clear();
+ cache.clear();
}
}
/**
- * Flush a single cache handler.
+ * Flush a single cache.
*/
- public static void clear(String handlerClass) {
+ public static void clear(String cacheId) {
- // loop through all handlers to find the one we want
- CacheHandler handler = null;
- Iterator handlers = cacheHandlers.iterator();
- while(handlers.hasNext()) {
- handler = (CacheHandler) handlers.next();
-
- if(handler.getClass().getName().equals(handlerClass)) {
- handler.clear();
- }
+ Cache cache = (Cache) caches.get(cacheId);
+ if(cache != null) {
+ cache.clear();
}
}
/**
- * Compile stats from all registered handlers.
+ * Compile stats from all registered caches.
*
* This is basically a hacky version of instrumentation which is being
* thrown in because we don't have a full instrumentation strategy yet.
@@ -386,12 +386,12 @@
Map allStats = new HashMap();
- CacheHandler handler = null;
- Iterator handlers = cacheHandlers.iterator();
- while(handlers.hasNext()) {
- handler = (CacheHandler) handlers.next();
+ Cache cache = null;
+ Iterator cachesIT = caches.values().iterator();
+ while(cachesIT.hasNext()) {
+ cache = (Cache) cachesIT.next();
- allStats.put(handler.getClass().getName(), handler.getStats());
+ allStats.put(cache.getId(), cache.getStats());
}
return allStats;
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringCacheEntry.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringCacheEntry.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringCacheEntry.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringCacheEntry.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheFactoryImpl.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheFactoryImpl.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheFactoryImpl.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -28,8 +28,7 @@
*/
public class ExpiringLRUCacheFactoryImpl implements CacheFactory {
- private static Log mLogger =
- LogFactory.getLog(ExpiringLRUCacheFactoryImpl.class);
+ private static Log log = LogFactory.getLog(ExpiringLRUCacheFactoryImpl.class);
// protected so only the CacheManager can instantiate us
@@ -43,6 +42,7 @@
int size = 100;
long timeout = 15 * 60;
+ String id = "unknown";
try {
size = Integer.parseInt((String) properties.get("size"));
@@ -56,11 +56,16 @@
// ignored
}
- Cache cache = new ExpiringLRUCacheImpl(size, timeout);
+ String cacheId = (String) properties.get("id");
+ if(cacheId != null) {
+ id = cacheId;
+ }
+
+ Cache cache = new ExpiringLRUCacheImpl(id, size, timeout);
- mLogger.debug("new cache constructed. size="+size+", timeout="+timeout);
+ log.debug("new cache constructed. size="+size+", timeout="+timeout);
return cache;
}
-}
\ No newline at end of file
+}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheImpl.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheImpl.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/ExpiringLRUCacheImpl.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -24,26 +24,24 @@
/**
* An LRU cache where entries expire after a given timeout period.
- *
- * @author Allen Gilliland
*/
public class ExpiringLRUCacheImpl extends LRUCacheImpl {
- private static Log mLogger = LogFactory.getLog(ExpiringLRUCacheImpl.class);
+ private static Log log = LogFactory.getLog(ExpiringLRUCacheImpl.class);
private long timeout = 0;
- protected ExpiringLRUCacheImpl() {
+ protected ExpiringLRUCacheImpl(String id) {
- super();
+ super(id);
this.timeout = 60 * 60 * 1000;
}
- protected ExpiringLRUCacheImpl(int maxsize, long timeout) {
+ protected ExpiringLRUCacheImpl(String id, int maxsize, long timeout) {
- super(maxsize);
+ super(id, maxsize);
// timeout is specified in seconds; only positive values allowed
if(timeout > 0) {
@@ -86,7 +84,8 @@
// if the value is null then that means this entry expired
if (value == null) {
- mLogger.debug("entry expired ["+key+"]");
+ log.debug("EXPIRED ["+key+"]");
+ hits--;
super.remove(key);
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -50,7 +50,7 @@
*/
public class FuturePostingsInvalidationJob implements Job {
- private static Log mLogger = LogFactory.getLog(FuturePostingsInvalidationJob.class);
+ private static Log log = LogFactory.getLog(FuturePostingsInvalidationJob.class);
// inputs from the user
private Map inputs = null;
@@ -63,7 +63,7 @@
public void execute() {
- mLogger.debug("starting");
+ log.debug("starting");
// notify the cache manager of an invalidation
if(nextExpirations != null) {
@@ -72,7 +72,7 @@
while(entries.hasNext()) {
entry = (WeblogEntryData) entries.next();
- mLogger.debug("expiring "+entry.getAnchor());
+ log.debug("expiring "+entry.getAnchor());
CacheManager.invalidate(entry);
}
@@ -92,7 +92,7 @@
cal.add(Calendar.MINUTE, this.peerTime);
Date end = cal.getTime();
- mLogger.debug("looking up entries between "+start+" and "+end);
+ log.debug("looking up entries between "+start+" and "+end);
// get all published entries between start and end date
expiringEntries = mgr.getWeblogEntries(null, null, start, end, null,
@@ -101,10 +101,10 @@
this.nextExpirations = expiringEntries;
} catch(Exception e) {
- mLogger.error(e);
+ log.error(e);
}
- mLogger.debug("finished");
+ log.debug("finished");
}
@@ -122,7 +122,7 @@
this.peerTime = pTime.intValue();
}
- mLogger.info("Peeking "+this.peerTime+" minutes into the future each pass");
+ log.info("Peeking "+this.peerTime+" minutes into the future each pass");
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheFactoryImpl.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheFactoryImpl.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheFactoryImpl.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
@@ -28,7 +28,7 @@
*/
public class LRUCacheFactoryImpl implements CacheFactory {
- private static Log mLogger = LogFactory.getLog(LRUCacheFactoryImpl.class);
+ private static Log log = LogFactory.getLog(LRUCacheFactoryImpl.class);
// protected so that only the CacheManager can instantiate us
@@ -41,6 +41,7 @@
public Cache constructCache(Map properties) {
int size = 100;
+ String id = "unknown";
try {
size = Integer.parseInt((String) properties.get("size"));
@@ -48,9 +49,14 @@
// ignored
}
- Cache cache = new LRUCacheImpl(size);
+ String cacheId = (String) properties.get("id");
+ if(cacheId != null) {
+ id = cacheId;
+ }
+
+ Cache cache = new LRUCacheImpl(id, size);
- mLogger.debug("new cache constructed. size="+size);
+ log.debug("new cache constructed. size="+size);
return cache;
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheImpl.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheImpl.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LRUCacheImpl.java Sun Jul 16 22:31:47 2006
@@ -1,29 +1,28 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -33,29 +32,45 @@
*/
public class LRUCacheImpl implements Cache {
- private static Log mLogger = LogFactory.getLog(LRUCacheImpl.class);
+ private static Log log = LogFactory.getLog(LRUCacheImpl.class);
+ private String id = null;
private Map cache = null;
+ // for metrics
+ double hits = 0;
+ double misses = 0;
+ double puts = 0;
+ double removes = 0;
+ Date startTime = new Date();
+
- protected LRUCacheImpl() {
+ protected LRUCacheImpl(String id) {
+ this.id = id;
this.cache = Collections.synchronizedMap(new LRULinkedHashMap(100));
}
- protected LRUCacheImpl(int maxsize) {
+ protected LRUCacheImpl(String id, int maxsize) {
+ this.id = id;
this.cache = Collections.synchronizedMap(new LRULinkedHashMap(maxsize));
}
+ public String getId() {
+ return this.id;
+ }
+
+
/**
* Store an entry in the cache.
*/
public synchronized void put(String key, Object value) {
this.cache.put(key, value);
+ puts++;
}
@@ -64,38 +79,55 @@
*/
public synchronized Object get(String key) {
- return this.cache.get(key);
+ Object obj = this.cache.get(key);
+
+ // for metrics
+ if(obj == null) {
+ misses++;
+ } else {
+ hits++;
+ }
+
+ return obj;
}
public synchronized void remove(String key) {
this.cache.remove(key);
- }
-
-
- public synchronized void remove(Set keys) {
-
- Iterator it = keys.iterator();
- while(it.hasNext())
- this.cache.remove((String) it.next());
+ removes++;
}
public synchronized void clear() {
this.cache.clear();
+
+ // clear metrics
+ hits = 0;
+ misses = 0;
+ puts = 0;
+ removes = 0;
+ startTime = new Date();
}
- public synchronized Set keySet() {
- return this.cache.keySet();
- }
-
-
- public Map stats() {
+ public Map getStats() {
+
+ Map stats = new HashMap();
+ stats.put("startTime", this.startTime);
+ stats.put("hits", new Double(this.hits));
+ stats.put("misses", new Double(this.misses));
+ stats.put("puts", new Double(this.puts));
+ stats.put("removes", new Double(this.removes));
+
+ // calculate efficiency
+ if((misses - removes) > 0) {
+ double efficiency = hits / (misses + hits);
+ stats.put("efficiency", new Double(efficiency * 100));
+ }
- return new HashMap();
+ return stats;
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LazyExpiringCacheEntry.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LazyExpiringCacheEntry.java?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LazyExpiringCacheEntry.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/cache/LazyExpiringCacheEntry.java Sun Jul 16 22:31:47 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.util.cache;
Modified: incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties?rev=422627&r1=422626&r2=422627&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/branches/roller_3.0/web/WEB-INF/classes/roller.properties Sun Jul 16 22:31:47 2006
@@ -147,19 +147,9 @@
# set "true" to NOT cache the custom pages for users who are logged in
cache.weblogpage.excludeOwnerEditPages=false
-# Weblog page last-modified-date cache
-# you want this fairly high, like weblogs * 10, with long timeouts
-cache.ifmodified.weblogpage.size=1000
-cache.ifmodified.weblogpage.timeout=14400
-
# Feed cache (xml feeds like rss, atom, etc)
cache.feed.size=200
cache.feed.timeout=3600
-
-# Feed last-modified-date cache
-# you want a reasonable size, like weblogs * 2, with long timeouts
-cache.ifmodified.feed.size=200
-cache.ifmodified.feed.timeout=14400
# Planet cache (planet page and rss feed)
cache.planet.size=10