Does this solve http://jira.magnolia.info/browse/MAGNOLIA-1657 ?

In any case, could you please report the changes on Jira ? (and possibly link to MAGNOLIA-1657 and resolve it?)

Thanks

g

On Nov 5, 2007, at 00:05 , [EMAIL PROTECTED] wrote:

Revision12194AuthorfgiustDate2007-11-05 00:05:08 +0100 (Mon, 05 Nov 2007)Log MessageAlign the ehcache implementation with the simple one (gzipped entries, observation) and cleanup usage of cache keys (it makes no sense anymore to use an object since it just wraps a string). This completes MAGNOLIA-636Modified Paths magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/BaseCacheManager.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/Cache.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/CacheFilter.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/CacheManager.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/DefaultCacheManager.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/ManageableCacheManager.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/RoleBasedCacheFilter.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/ehcache/CacheImpl.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/noop/NoOpCache.java magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/simple/CacheImpl.java magnolia/trunk/magnolia-module-cache/src/main/resources/mgnl- bootstrap/cache/config.modules.cache.config.ehcache.xml
Removed Paths
magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/CacheKey.java
Diff
Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/BaseCacheManager.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/BaseCacheManager.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/BaseCacheManager.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -59,7 +59,7 @@ return this.config; } - public final long getCreationTime(CacheKey key) {+ public final long getCreationTime(String key) { try { return doGetCreationTime(key); }@@ -270,7 +270,7 @@ log.info("CacheManager is now stopped."); } - public final boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ public final boolean streamFromCache (String key, HttpServletResponse response, boolean canCompress) { if (log.isDebugEnabled()) { log.debug("Streaming from cache {}, {}", key, canCompress ? "compressed" : "not compressed"); }@@ -295,14 +295,14 @@ * method are logged as an error but are not propagated. * @see BaseCacheManager#handleNonFatalException(Exception) */- protected abstract long doGetCreationTime(CacheKey request);+ protected abstract long doGetCreationTime(String key); / ** * Template method to be implemented by subclasses. Should not throw any exceptions. All exceptions thrown by this * method are logged as an error but are not propagated. * @see BaseCacheManager#handleNonFatalException(Exception) */- protected abstract boolean doStreamFromCache(CacheKey request, HttpServletResponse response, boolean canCompress);+ protected abstract boolean doStreamFromCache(String key, HttpServletResponse response, boolean canCompress); /** * Template method to be implemented by subclasses. Should not throw any exceptions. All exceptions thrown by this Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/Cache.java (12193 => 12194)--- magnolia/trunk/ magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ Cache.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/ magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ Cache.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -18,15 +18,15 @@ void stop(); - boolean isCached(CacheKey key);+ boolean isCached(String key); - void cacheRequest(CacheKey key, CacheableEntry out, boolean canCompress);+ void cacheRequest (String key, CacheableEntry out, boolean canCompress); - boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress);+ boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress); - long getCreationTime(CacheKey key);+ long getCreationTime(String key); - void remove(CacheKey key);+ void remove(String key); void flush(); Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/CacheFilter.java (12193 => 12194)--- magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheFilter.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheFilter.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -57,7 +57,7 @@ // cache // if this time there are parameters. if (cacheable) {- CacheKey key = this.getCacheKey(request);+ String key = this.getCacheKey(request); if (!this.ifModifiedSince (request, cacheManager.getCreationTime(key))) { response.setStatus (HttpServletResponse.SC_NOT_MODIFIED); return;@@ -120,7 +120,7 @@ /** * @return computed cache key */- public CacheKey getCacheKey(HttpServletRequest request) {+ public String getCacheKey(HttpServletRequest request) { return getCacheManager().getCacheKey (request); } Deleted: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/CacheKey.java (12193 => 12194)--- magnolia/trunk/ magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheKey.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheKey.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -1,74 +0,0 @@- package info.magnolia.cms.cache; - -import info.magnolia.context.MgnlContext; - -import java.io.Serializable; - -import javax.servlet.http.HttpServletRequest; - - -/** - * @author Fabrizio Giustina - * @version $Revision$ ($Author$) - */ - public class CacheKey implements Serializable { - - /** - * Stable serialVersionUID. - */ - private static final long serialVersionUID = 222L; - - private String key; - - /** - * Used for special subclasses not meant to be used in general - */ - public CacheKey() { - } - - /** - * Contstuctor used if the key is already known - */ - public CacheKey(String key) { - this.key = key; - } - - /** - * override actual key value - */ - public void setValue (String key) { - this.key = key; - } - - /** - * The constructor used by default - * @param request the request from which we get the path TODO : we should probably use the AggregationState instead - * of the HttpServletRequest - */ - public CacheKey(HttpServletRequest request) { - key = MgnlContext.getAggregationState().getOriginalURI(); - } - - / ** - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - return key.equals (((CacheKey) obj).key); - } - - /** - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return key.hashCode(); - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - // just return the key (path), as it's used for the filepath in the simple implementation - return key; - } - -} Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/CacheManager.java (12193 => 12194)--- magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheManager.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ CacheManager.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -16,9 +16,9 @@ */ public interface CacheManager { - boolean cacheRequest (CacheKey key, CacheableEntry entry, boolean canCompress);+ boolean cacheRequest(String key, CacheableEntry entry, boolean canCompress); - CacheKey getCacheKey(HttpServletRequest request); + String getCacheKey(HttpServletRequest request); boolean isCacheable(HttpServletRequest request); @@ -26,7 +26,7 @@ void flushAll(); - long getCreationTime(CacheKey request);+ long getCreationTime(String key); void init(Content content) throws ConfigurationException; @@ -48,5 +48,5 @@ void stop(); - boolean streamFromCache(CacheKey request, HttpServletResponse response, boolean canCompress);+ boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress); } Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/DefaultCacheManager.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/DefaultCacheManager.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/DefaultCacheManager.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -1,10 +1,15 @@ package info.magnolia.cms.cache; import info.magnolia.cms.beans.config.ConfigurationException; +import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.cache.noop.NoOpCache; import info.magnolia.cms.util.ClassUtil;+import info.magnolia.cms.util.ObservationUtil; +import info.magnolia.context.MgnlContext; import info.magnolia.voting.Voting; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,8 +35,8 @@ * @see info.magnolia.cms.cache.CacheManager#getCacheKey (javax.servlet.http.HttpServletRequest) TODO : we should * probably use the AggregationState instead of the HttpServletRequest */- public CacheKey getCacheKey (HttpServletRequest request) { - return new CacheKey (request);+ public String getCacheKey(HttpServletRequest request) { + return MgnlContext.getAggregationState ().getOriginalURI(); } /**@@ -53,7 +58,7 @@ return getConfig().canCompress(extension); } - public boolean cacheRequest(CacheKey key, CacheableEntry entry, boolean canCompress) {+ public boolean cacheRequest(String key, CacheableEntry entry, boolean canCompress) { cache.cacheRequest(key, entry, canCompress); return true; }@@ -62,8 +67,8 @@ this.cache.flush (); } - protected long doGetCreationTime(CacheKey request) { - return this.cache.getCreationTime(request);+ protected long doGetCreationTime(String key) { + return this.cache.getCreationTime(key); } protected void doStart () {@@ -74,6 +79,8 @@ cache.start(config); this.cache = cache;+ + registerObservation (); } catch (ConfigurationException e) { // FIXME@@ -85,7 +92,7 @@ this.cache = NOOP_CACHE; } - protected boolean doStreamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ protected boolean doStreamFromCache(String key, HttpServletResponse response, boolean canCompress) { if (!isRunning()) { return false; }@@ -108,7 +115,7 @@ return this.cache; } - private boolean isCached(CacheKey request) {+ private boolean isCached(String request) { return this.cache.isCached(request); } @@ -130,4 +137,25 @@ } } + /** + * override this to register different workspaces + */ + protected void registerObservation() { + // TODO this should be more flexible in cases you want to handle events on other repositories + // register to observe on any changes if configured + ObservationUtil.registerDefferedChangeListener (ContentRepository.WEBSITE, "/", new EventListener() { + + public void onEvent(EventIterator events) { + handleChangeEvents(events); + } + }, 5000, 30000); + } + + /** + * Called based on the observation. The default implementation flushes the whole cache. + */ + protected void handleChangeEvents (EventIterator events) { + flushAll(); + } + } Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/ManageableCacheManager.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/ManageableCacheManager.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/ManageableCacheManager.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -40,7 +40,7 @@ this.cacheManager = cacheManager; } - public boolean cacheRequest(CacheKey key, CacheableEntry entry, boolean canCompress) {+ public boolean cacheRequest(String key, CacheableEntry entry, boolean canCompress) { boolean didCache = this.cacheManager.cacheRequest(key, entry, canCompress); if (didCache) {@@ -66,7 +66,7 @@ return this.cachePuts; } - public long getCreationTime(CacheKey request) {+ public long getCreationTime (String request) { return this.cacheManager.getCreationTime (request); } @@ -135,11 +135,11 @@ return this.cacheManager.canCompress(request); } - public CacheKey getCacheKey(HttpServletRequest request) {+ public String getCacheKey(HttpServletRequest request) { return this.cacheManager.getCacheKey(request); } - public boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ public boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress) { boolean didUseCache = this.cacheManager.streamFromCache (key, response, canCompress); if (didUseCache) { Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/RoleBasedCacheFilter.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/RoleBasedCacheFilter.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/RoleBasedCacheFilter.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -12,12 +12,13 @@ */ package info.magnolia.cms.cache; +import info.magnolia.cms.security.Digester; import info.magnolia.context.MgnlContext;-import info.magnolia.cms.security.Digester; -import javax.servlet.http.HttpServletRequest; import java.util.Collection; +import javax.servlet.http.HttpServletRequest; + import org.apache.commons.lang.ArrayUtils; @@ -30,9 +31,9 @@ * This will: - Consolidate all roles sorted by node name - Generate MD5 of this consolidated string - Adds this MD5 * to the key generated by cache manager */- public CacheKey getCacheKey (HttpServletRequest request) {+ public String getCacheKey (HttpServletRequest request) { String key = MgnlContext.getAggregationState().getCurrentURI();- return this.generateMD5Key(MgnlContext.getUser().getAllRoles(), new CacheKey(key));+ return this.generateMD5Key (MgnlContext.getUser().getAllRoles(), key); } /**@@ -40,11 +41,10 @@ * @param assignedRoles * @param key as created by configured CacheManager */- private CacheKey generateMD5Key(Collection assignedRoles, CacheKey key) {+ private String generateMD5Key(Collection assignedRoles, String key) { String asString = ArrayUtils.toString (assignedRoles);- StringBuffer buffer = new StringBuffer (key.toString()).append(".").append(Digester.getMD5Hex(asString)); - key.setValue(new String(buffer)); - return key; + StringBuffer buffer = new StringBuffer(key).append (".").append(Digester.getMD5Hex(asString)); + return buffer.toString(); } } Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/ehcache/CacheImpl.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/ehcache/CacheImpl.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/ehcache/CacheImpl.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -2,14 +2,15 @@ import info.magnolia.cms.beans.config.ConfigurationException; import info.magnolia.cms.cache.CacheConfig;-import info.magnolia.cms.cache.CacheKey; import info.magnolia.cms.cache.CacheableEntry; import info.magnolia.cms.core.Content; import info.magnolia.cms.core.Path; import java.io.ByteArrayInputStream;+import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream;+import java.util.zip.GZIPOutputStream; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletResponse;@@ -44,8 +45,27 @@ private CacheManager ehcacheManager; - public void cacheRequest (CacheKey key, CacheableEntry out, boolean canCompress) { - this.ehcache.put(new Element(key, out));+ public void cacheRequest(String key, CacheableEntry entry, boolean canCompress) { + this.ehcache.put(new Element(key, entry)); + + if (canCompress) { + + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream out = new GZIPOutputStream(baos); + out.write(entry.getOut()); + out.flush(); + + CacheableEntry compressedEntry = new CacheableEntry(baos.toByteArray()); + compressedEntry.setContentType(entry.getContentType()); + compressedEntry.setCharacterEncoding (entry.getCharacterEncoding()); + this.ehcache.put (new Element(compressedKey(key), compressedEntry)); + } + catch (IOException e) { + log.warn ("Failed to cache " + key, e); + } + } + } public void flush() {@@ -55,11 +75,11 @@ /** * Remove the entry */- public void remove(CacheKey key) {+ public void remove(String key) { this.ehcache.remove (key); } - public long getCreationTime(CacheKey key) {+ public long getCreationTime(String key) { try { Element element = this.ehcache.get(key); @@ -86,7 +106,7 @@ } } - public boolean isCached(CacheKey request) {+ public boolean isCached(String request) { try { Element element = this.ehcache.getQuiet (request); @@ -101,9 +121,11 @@ this.ehcacheManager.shutdown (); } - public boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ public boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress) { + + String actualKey = canCompress ? compressedKey(key) : key; try {- Element element = this.ehcache.get(key);+ Element element = this.ehcache.get(actualKey); if (element == null) { return false; }@@ -111,6 +133,9 @@ byte[] buffer = ((CacheableEntry) element.getValue ()).getOut(); ByteArrayInputStream in = new ByteArrayInputStream(buffer); response.setContentLength (buffer.length);+ if (canCompress) { + response.setHeader("Content-Encoding", "gzip"); + } try { OutputStream out = response.getOutputStream();@@ -119,7 +144,11 @@ IOUtils.closeQuietly(out); } catch (IOException e) {- log.error("Error while reading cache for: '" + key + "'.", e);+ // usually a ClientAbortException + log.debug("Error while reading cache for: {}: {} {}", new Object[]{ + key, + e.getClass().getName(), + e.getMessage()}); return false; } finally {@@ -129,7 +158,8 @@ return true; } catch (CacheException e) {- throw new RuntimeException(e);+ log.warn ("Failed to stream from cache " + key, e); + return false; } } @@ -181,4 +211,8 @@ } } + private String compressedKey(String key) { + return key + ". $.gzip"; + } + } Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/noop/NoOpCache.java (12193 => 12194)--- magnolia/ trunk/magnolia-module-cache/src/main/java/info/magnolia/cms/cache/ noop/NoOpCache.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/noop/NoOpCache.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -2,7 +2,6 @@ import info.magnolia.cms.cache.Cache; import info.magnolia.cms.cache.CacheConfig;-import info.magnolia.cms.cache.CacheKey; import info.magnolia.cms.cache.CacheableEntry; import javax.servlet.http.HttpServletRequest;@@ -47,7 +46,7 @@ * Does nothing. * @return <code>false</code> */- public boolean isCached(CacheKey request) {+ public boolean isCached (String request) { return false; } @@ -69,14 +68,14 @@ * @see info.magnolia.cms.cache.Cache#cacheRequest (info.magnolia.cms.cache.CacheKey, * info.magnolia.cms.cache.CacheableEntry, boolean) */- public void cacheRequest(CacheKey key, CacheableEntry out, boolean canCompress) {+ public void cacheRequest(String key, CacheableEntry out, boolean canCompress) { } /** * @see info.magnolia.cms.cache.Cache#getCreationTime (info.magnolia.cms.cache.CacheKey) */- public long getCreationTime(CacheKey request) {+ public long getCreationTime (String request) { return 0; } @@ -84,14 +83,14 @@ * @see info.magnolia.cms.cache.Cache#streamFromCache (info.magnolia.cms.cache.CacheKey, * javax.servlet.http.HttpServletResponse, boolean) */- public boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ public boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress) { return false; } /** * @see info.magnolia.cms.cache.Cache#flushEntry (info.magnolia.cms.cache.CacheKey) */- public void remove (CacheKey key) {+ public void remove(String key) { } Modified: magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/simple/CacheImpl.java (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/java/info/magnolia/ cms/cache/simple/CacheImpl.java 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/java/info/ magnolia/cms/cache/simple/CacheImpl.java 2007-11-04 23:05:08 UTC (rev 12194)@@ -3,7 +3,6 @@ import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.cache.Cache; import info.magnolia.cms.cache.CacheConfig;-import info.magnolia.cms.cache.CacheKey; import info.magnolia.cms.cache.CacheManagerFactory; import info.magnolia.cms.cache.CacheableEntry; import info.magnolia.cms.core.Path;@@ -64,7 +63,7 @@ * @param entry * @param canCompress */- public void cacheRequest (CacheKey key, CacheableEntry entry, boolean canCompress) {+ public void cacheRequest(String key, CacheableEntry entry, boolean canCompress) { // This implementation flushes entire cache, its safe to simply check on one flag, for other // implementations we need to check and synchronize on CacheKey if (currentlyRemoving) {@@ -98,7 +97,7 @@ * @param entry * @param file */- private long cacheSingleFile(CacheKey key, CacheableEntry entry, File file, boolean compress) {+ private long cacheSingleFile(String key, CacheableEntry entry, File file, boolean compress) { // it should not cache again if the resource already existing // its a responsibility of a cache manager to call remove or flush if resource needs to be invalidated if (!file.exists()) {@@ -109,7 +108,7 @@ try { boolean parentDirectoryReady = mkdirs(file.getParentFile ()); if (!parentDirectoryReady) {- log.warn("Failed to cache {}, unable to create parent directory {}", key.toString(), file + log.warn("Failed to cache {}, unable to create parent directory {}", key, file .getParentFile () .getAbsolutePath()); return 0;@@ -124,7 +123,7 @@ out.flush (); } catch (IOException e) {- log.warn("Failed to cache " + key.toString() + " to " + file.getAbsolutePath(), e);+ log.warn("Failed to cache " + key + " to " + file.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(out);@@ -161,7 +160,7 @@ } } - public long getCreationTime(CacheKey key) {+ public long getCreationTime(String key) { CachedItem item = (CachedItem) this.cachedURIList.get(key); if (item == null) { return -1;@@ -173,8 +172,6 @@ public void start(CacheConfig config) { this.config = config; - registerObservation(); - File cacheDir = getCacheDirectory(); if (!cacheDir.exists()) {@@ -189,27 +186,6 @@ } /**- * override this to register different workspaces - */ - protected void registerObservation() { - // TODO this should be more flexible in cases you want to handle events on other repositories - // register to observe on any changes if configured - ObservationUtil.registerDefferedChangeListener (ContentRepository.WEBSITE, "/", new EventListener() { - - public void onEvent(EventIterator events) { - handleChangeEvents(events); - } - }, 5000, 30000); - } - - /** - * Called based on the observation. The default implementation flushes the whole cache. - */ - protected void handleChangeEvents (EventIterator events) { - CacheManagerFactory.getCacheManager().flushAll(); - } - - / ** * synchronize file system with in-memory cache list * @param cacheDir */@@ -232,13 +208,13 @@ if (compressedFile.exists()) { compressedSize = (int) compressedFile.length (); }- addToCachedURIList (new CacheKey(key), item.lastModified(), size, compressedSize); + addToCachedURIList(key, item.lastModified(), size, compressedSize); } } } } - public boolean isCached(CacheKey key) {+ public boolean isCached(String key) { return this.cachedURIList.get(key) ! = null; } @@ -255,7 +231,7 @@ * @param response HttpServletResponse * @return <code>true</code> is successful */- public boolean streamFromCache(CacheKey key, HttpServletResponse response, boolean canCompress) {+ public boolean streamFromCache(String key, HttpServletResponse response, boolean canCompress) { FileInputStream fin = null; OutputStream out = null;@@ -285,7 +261,11 @@ out.flush (); } catch (IOException e) {- log.debug ("Error while reading cache for: '" + key + "'.", e); + // usually a ClientAbortException + log.debug("Error while reading cache for: {}: {} {}", new Object[] { + key, + e.getClass().getName(), + e.getMessage()}); return false; } finally {@@ -302,7 +282,7 @@ * @param compressedSize compressed size * @param lastModified */- private void addToCachedURIList(CacheKey key, long lastModified, int size, int compressedSize) {+ private void addToCachedURIList(String key, long lastModified, int size, int compressedSize) { CachedItem entry = new CachedItem (lastModified, size, compressedSize); if (log.isDebugEnabled()) {@@ -320,7 +300,7 @@ * Empties the cache for the specified resource. Currenty it expects the entire path, including cache location. This * is never used for simple cache since there are no way to find out how to flush related items */- public void remove(CacheKey key) {+ public void remove(String key) { File file = this.getFile (key, false); try { if (file.isDirectory()) {@@ -344,7 +324,7 @@ /** * @return size as on disk */- private int getCompressedSize(CacheKey key) {+ private int getCompressedSize(String key) { CachedItem item = (CachedItem) this.cachedURIList.get(key); if (item == null) { return -1;@@ -353,8 +333,8 @@ return item.compressedSize; } - private File getFile(CacheKey key, boolean compressed) { - String fileName = key.toString(); + private File getFile(String key, boolean compressed) { + String fileName = key; // we add .cache extension to directories to distinguish them from files cached without extensions fileName = StringUtils.removeStart ( StringUtils.replace(fileName, "/", CACHE_DIRECTORY_EXTENTION + "/"),@@ -372,7 +352,7 @@ /** * @return size as on disk */- private int getSize(CacheKey key) {+ private int getSize(String key) { CachedItem item = (CachedItem) this.cachedURIList.get(key); if (item == null) { return -1;@@ -384,7 +364,7 @@ /** * @param key */- private void removeFromCachedURIList (CacheKey key) {+ private void removeFromCachedURIList(String key) { this.cachedURIList.remove(key); } Modified: magnolia/trunk/magnolia-module-cache/src/main/resources/ mgnl-bootstrap/cache/config.modules.cache.config.ehcache.xml (12193 => 12194)--- magnolia/trunk/magnolia-module-cache/src/main/ resources/mgnl-bootstrap/cache/ config.modules.cache.config.ehcache.xml 2007-11-04 22:08:43 UTC (rev 12193) +++ magnolia/trunk/magnolia-module-cache/src/main/ resources/mgnl-bootstrap/cache/ config.modules.cache.config.ehcache.xml 2007-11-04 23:05:08 UTC (rev 12194)@@ -15,27 +15,36 @@ <sv:property sv:name="mgnl:uuid" sv:type="String"> <sv:value>2e26541b-98b4-11da- bd92-3383a88182be</sv:value> </sv:property>- <sv:property sv:name="diskPersistent" sv:type="String">+ <sv:property sv:name="diskPersistent" sv:type="Boolean"> <sv:value>true</ sv:value> </sv:property>- <sv:property sv:name="eternal" sv:type="String">+ <sv:property sv:name="eternal" sv:type="Boolean"> <sv:value>true</sv:value> </sv:property>- <sv:property sv:name="timeToLiveSeconds" sv:type="String">+ <sv:property sv:name="timeToLiveSeconds" sv:type="Long"> <sv:value>0</sv:value> </sv:property>- <sv:property sv:name="maxElementsInMemory" sv:type="String"> - <sv:value>10</ sv:value>+ <sv:property sv:name="memoryStoreEvictionPolicy" sv:type="String"> + <sv:value>LFU</sv:value> </sv:property>- <sv:property sv:name="diskExpiryThreadIntervalSeconds" sv:type="String">+ <sv:property sv:name="maxElementsInMemory" sv:type="Long"> + <sv:value>50</sv:value> + </sv:property> + <sv:property sv:name="diskExpiryThreadIntervalSeconds" sv:type="Long"> <sv:value>120</sv:value> </sv:property>- <sv:property sv:name="overflowToDisk" sv:type="String">+ <sv:property sv:name="overflowToDisk" sv:type="Boolean"> <sv:value>true</sv:value> </sv:property>- <sv:property sv:name="timeToIdleSeconds" sv:type="String">+ <sv:property sv:name="timeToIdleSeconds" sv:type="Long"> <sv:value>0</ sv:value> </sv:property>+ <sv:property sv:name="maxElementsOnDisk" sv:type="Long"> + <sv:value>0</ sv:value> + </sv:property> + <sv:property sv:name="diskSpoolBufferSizeMB" sv:type="Long"> + <sv:value>30</ sv:value> + </sv:property> <sv:node sv:name="MetaData"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>mgnl:metaData</sv:value>



----------------------------------------------------------------
for list details see
http://documentation.magnolia.info/docs/en/editor/stayupdated.html
----------------------------------------------------------------

Reply via email to