You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by me...@apache.org on 2013/09/03 19:42:54 UTC
svn commit: r1519765 [1/2] - in /jspwiki/trunk: ./ jspwiki-war/
jspwiki-war/src/main/config/doc/ jspwiki-war/src/main/java/org/apache/wiki/
jspwiki-war/src/main/java/org/apache/wiki/attachment/
jspwiki-war/src/main/java/org/apache/wiki/providers/ jspwi...
Author: metskem
Date: Tue Sep 3 17:42:53 2013
New Revision: 1519765
URL: http://svn.apache.org/r1519765
Log:
2013-09-03 Harry Metske (metskem@apache.org)
* 2.10.0-svn-45
* fixed JSPWIKI-792, replace opensymphony's oscache with ehcache
Removed:
jspwiki/trunk/jspwiki-war/src/main/config/doc/LICENSE.OpenSymphony
jspwiki/trunk/jspwiki-war/src/main/resources/oscache.properties
Modified:
jspwiki/trunk/ChangeLog
jspwiki/trunk/LICENSE
jspwiki/trunk/jspwiki-war/pom.xml
jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java
jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingProvider.java
jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/render/RenderingManager.java
jspwiki/trunk/jspwiki-war/src/main/webapp/SisterSites.jsp
jspwiki/trunk/jspwiki-war/src/main/webapp/rss.jsp
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/content/PageRenamerTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/RecentChangesPluginTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/providers/CachingProviderTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/render/RenderingManagerTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/rss/RSSGeneratorTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/search/SearchManagerTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/stress/MassiveRepositoryTest.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/stress/StressTestVersioningProvider.java
jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/xmlrpc/RPCHandlerTest.java
jspwiki/trunk/pom.xml
Modified: jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/jspwiki/trunk/ChangeLog?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/ChangeLog (original)
+++ jspwiki/trunk/ChangeLog Tue Sep 3 17:42:53 2013
@@ -1,3 +1,9 @@
+2013-09-03 Harry Metske (metskem@apache.org)
+
+ * 2.10.0-svn-45
+
+ * fixed JSPWIKI-792, replace opensymphony's oscache with ehcache
+
2013-08-25 Glen Mazza (gmazza AT apache DOT org)
* 2.10.0-svn-44
Modified: jspwiki/trunk/LICENSE
URL: http://svn.apache.org/viewvc/jspwiki/trunk/LICENSE?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/LICENSE (original)
+++ jspwiki/trunk/LICENSE Tue Sep 3 17:42:53 2013
@@ -230,7 +230,7 @@ lucene-memory-4.4.0.jar
mail-1.4.7.jar doc/LICENSE.cddl
nekohtml-0.9.5.jar LICENSE
oro-2.0.8.jar LICENSE
-oscache-2.3.jar doc/LICENSE.OpenSymphony
+ehcache-core-2.6.6.jar LICENSE
sandler-0.5.jar doc/LICENSE.sandler
servlet-api-2.5.jar doc/LICENSE.cddl
xmlrpc-2.0.1.jar LICENSE
Modified: jspwiki/trunk/jspwiki-war/pom.xml
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/pom.xml?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/pom.xml (original)
+++ jspwiki/trunk/jspwiki-war/pom.xml Tue Sep 3 17:42:53 2013
@@ -71,10 +71,9 @@
</dependency>
<dependency>
- <groupId>opensymphony</groupId>
- <artifactId>oscache</artifactId>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache-core</artifactId>
</dependency>
-
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
@@ -90,6 +89,11 @@
<artifactId>log4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
<dependency>
<groupId>com.metaparadigm</groupId>
<artifactId>json-rpc</artifactId>
@@ -237,6 +241,7 @@
- use UglifyJS for JS compression
- use Less as advanced CSS preprocessor
-->
+
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java Tue Sep 3 17:42:53 2013
@@ -22,6 +22,7 @@ import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
+import net.sf.ehcache.CacheManager;
import org.apache.log4j.Logger;
import org.apache.wiki.url.DefaultURLConstructor;
@@ -64,6 +65,7 @@ public class WikiServlet
public void destroy()
{
log.info("WikiServlet shutdown.");
+ CacheManager.getInstance().shutdown();
m_engine.shutdown();
super.destroy();
}
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java Tue Sep 3 17:42:53 2013
@@ -24,6 +24,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.wiki.*;
@@ -33,9 +36,6 @@ import org.apache.wiki.providers.Provide
import org.apache.wiki.providers.WikiAttachmentProvider;
import org.apache.wiki.util.ClassUtil;
-import com.opensymphony.oscache.base.Cache;
-import com.opensymphony.oscache.base.NeedsRefreshException;
-
/**
* Provides facilities for handling attachments. All attachment
* handling goes through this class.
@@ -71,6 +71,16 @@ public class AttachmentManager
static Logger log = Logger.getLogger( AttachmentManager.class );
private WikiAttachmentProvider m_provider;
private WikiEngine m_engine;
+ private CacheManager m_cacheManager = CacheManager.getInstance();
+
+ private Cache m_dynamicAttachments;
+ /** Name of the page cache. */
+ public static final String CACHE_NAME = "jspwiki.dynamicAttachmentCache";
+
+ /** The capacity of the cache, if you want something else, tweak ehcache.xml. */
+ public static final int DEFAULT_CACHECAPACITY = 1000;
+ private int expiryPeriod = 24*60*60;
+
/**
* Creates a new AttachmentManager. Note that creation will never fail,
@@ -119,16 +129,21 @@ public class AttachmentManager
//
// Create and initialize the provider.
//
- try
- {
- Class<?> providerclass = ClassUtil.findClass( "org.apache.wiki.providers",
- classname );
+ try {
+ if (m_cacheManager.cacheExists(CACHE_NAME)) {
+ m_dynamicAttachments = m_cacheManager.getCache(CACHE_NAME);
+ } else {
+ log.info("cache with name " + CACHE_NAME + " not found in ehcache.xml, creating it with defaults.");
+ m_dynamicAttachments = new Cache(CACHE_NAME, DEFAULT_CACHECAPACITY, false, false, expiryPeriod, expiryPeriod);
+ m_cacheManager.addCache(m_dynamicAttachments);
+ }
- m_provider = (WikiAttachmentProvider)providerclass.newInstance();
+ Class<?> providerclass = ClassUtil.findClass("org.apache.wiki.providers", classname);
- m_provider.initialize( m_engine, props );
- }
- catch( ClassNotFoundException e )
+ m_provider = (WikiAttachmentProvider) providerclass.newInstance();
+
+ m_provider.initialize(m_engine, props);
+ } catch( ClassNotFoundException e )
{
log.error( "Attachment provider class not found",e);
}
@@ -392,7 +407,7 @@ public class AttachmentManager
return m_provider.getAttachmentData( att );
}
- private Cache m_dynamicAttachments = new Cache( true, false, false );
+
/**
* Stores a dynamic attachment. Unlike storeAttachment(), this just stores
@@ -403,7 +418,7 @@ public class AttachmentManager
*/
public void storeDynamicAttachment( WikiContext ctx, DynamicAttachment att )
{
- m_dynamicAttachments.putInCache( att.getName(), att );
+ m_dynamicAttachments.put(new Element(att.getName(), att));
}
/**
@@ -415,18 +430,15 @@ public class AttachmentManager
* @see #getAttachmentInfo(String)
*/
- public DynamicAttachment getDynamicAttachment( String name )
- {
- try
- {
- return (DynamicAttachment) m_dynamicAttachments.getFromCache( name );
- }
- catch( NeedsRefreshException e )
- {
+ public DynamicAttachment getDynamicAttachment(String name) {
+ Element element = m_dynamicAttachments.get(name);
+ if (element != null) {
+ return (DynamicAttachment) element.getObjectValue();
+ } else {
//
// Remove from cache, it has expired.
//
- m_dynamicAttachments.putInCache( name, null );
+ m_dynamicAttachments.put(new Element(name, null));
return null;
}
@@ -482,7 +494,7 @@ public class AttachmentManager
//
// Checks if the actual, real page exists without any modifications
- // or aliases. We cannot store an attachment to a non-existant page.
+ // or aliases. We cannot store an attachment to a non-existent page.
//
if( !m_engine.getPageManager().pageExists( att.getParentName() ) )
{
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java Tue Sep 3 17:42:53 2013
@@ -22,6 +22,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
import org.apache.wiki.*;
import org.apache.wiki.attachment.Attachment;
@@ -29,11 +32,6 @@ import org.apache.wiki.attachment.Attach
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.TextUtil;
-import com.opensymphony.oscache.base.Cache;
-import com.opensymphony.oscache.base.CacheEntry;
-import com.opensymphony.oscache.base.NeedsRefreshException;
-import com.opensymphony.oscache.base.events.*;
-
/**
* Provides a caching attachment provider. This class rests on top of a
* real provider class and provides a cache to speed things up. Only the
@@ -43,9 +41,6 @@ import com.opensymphony.oscache.base.eve
* @since 2.1.64.
*/
-// FIXME: Do we need to clear the cache entry if we get an NRE and the attachment is not there?
-// FIXME: We probably clear the cache a bit too aggressively in places.
-// FIXME: Does not yet react well to external cache changes. Should really use custom
// EntryRefreshPolicy for that.
public class CachingAttachmentProvider
implements WikiAttachmentProvider
@@ -54,32 +49,39 @@ public class CachingAttachmentProvider
private WikiAttachmentProvider m_provider;
+ private CacheManager m_cacheManager = CacheManager.getInstance();
+
+ /** Default cache capacity for now. */
+ public static final int m_capacity = 1000;
+ /** Default expiry period for now. */
+ private int m_pageContentExpiryPeriod = 24*60*60;
+
/**
* The cache contains Collection objects which contain Attachment objects.
* The key is the parent wiki page name (String).
*/
private Cache m_cache;
-
- private long m_cacheMisses = 0;
- private long m_cacheHits = 0;
+ /** Name of the attachment cache. */
+ public static final String ATTCOLLCACHE_NAME = "jspwiki.attachmentCollectionsCache";
/**
* This cache contains Attachment objects and is keyed by attachment name.
* This provides for quickly giving recently changed attachments (for the RecentChanges plugin)
*/
private Cache m_attCache;
+ /** Name of the attachment cache. */
+ public static final String ATTCACHE_NAME = "jspwiki.attachmentsCache";
+
+ private long m_cacheMisses = 0;
+ private long m_cacheHits = 0;
/** The extension to append to directory names to denote an attachment directory. */
public static final String DIR_EXTENSION = "-att";
/** Property that supplies the directory used to store attachments. */
public static final String PROP_STORAGEDIR = "jspwiki.basicAttachmentProvider.storageDir";
-
- // FIXME: Make settable.
- private int m_refreshPeriod = 60*10; // 10 minutes at the moment
private boolean m_gotall = false;
- private CachedAttachmentCollector m_allCollector = new CachedAttachmentCollector();
/**
* {@inheritDoc}
@@ -90,17 +92,22 @@ public class CachingAttachmentProvider
{
log.info("Initing CachingAttachmentProvider");
- //
- // Construct an unlimited cache of Collection objects
- //
- m_cache = new Cache( true, false, true );
+ if (m_cacheManager.cacheExists(ATTCOLLCACHE_NAME)) {
+ m_cache = m_cacheManager.getCache(ATTCOLLCACHE_NAME);
+ } else {
+ m_cache = new Cache(ATTCOLLCACHE_NAME, m_capacity, false, false, m_pageContentExpiryPeriod, m_pageContentExpiryPeriod);
+ m_cacheManager.addCache(m_cache);
+ }
//
- // Construct an unlimited cache for the individual Attachment objects.
- // Attachment name is key, the Attachment object is the cached object
+ // cache for the individual Attachment objects, attachment name is key, the Attachment object is the cached object
//
- m_attCache = new Cache(true, false, true);
- m_attCache.addCacheEventListener(m_allCollector,CacheEntryEventListener.class);
+ if (m_cacheManager.cacheExists(ATTCACHE_NAME)) {
+ m_attCache = m_cacheManager.getCache(ATTCACHE_NAME);
+ } else {
+ m_attCache = new Cache(ATTCACHE_NAME, m_capacity, false, false, m_pageContentExpiryPeriod, m_pageContentExpiryPeriod);
+ m_cacheManager.addCache(m_attCache);
+ }
//
// Find and initialize real provider.
@@ -109,8 +116,7 @@ public class CachingAttachmentProvider
try
{
- Class providerclass = ClassUtil.findClass( "org.apache.wiki.providers",
- classname );
+ Class providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
m_provider = (WikiAttachmentProvider)providerclass.newInstance();
@@ -139,70 +145,39 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
public void putAttachmentData( Attachment att, InputStream data )
- throws ProviderException,
- IOException
- {
+ throws ProviderException, IOException {
m_provider.putAttachmentData( att, data );
- m_cache.removeEntry( att.getParentName() );
+ m_cache.remove(att.getParentName());
att.setLastModified(new Date());
- m_attCache.putInCache(att.getName(), att);
+ m_attCache.put(new Element(att.getName(), att));
}
/**
* {@inheritDoc}
*/
public InputStream getAttachmentData( Attachment att )
- throws ProviderException,
- IOException
- {
+ throws ProviderException, IOException {
return m_provider.getAttachmentData( att );
}
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
- public Collection listAttachments( WikiPage page )
- throws ProviderException
- {
- log.debug("Listing attachments for "+page);
- try
- {
- Collection<Attachment> c = (Collection<Attachment>)m_cache.getFromCache( page.getName(), m_refreshPeriod );
+ public Collection listAttachments(WikiPage page) throws ProviderException {
+ log.debug("Listing attachments for " + page);
+ Collection<Attachment> c = null;
+ Element element = m_cache.get(page.getName());
- if( c != null )
- {
- log.debug("LIST from cache, "+page.getName()+", size="+c.size());
- m_cacheHits++;
- return cloneCollection(c);
- }
-
- log.debug("list NOT in cache, "+page.getName());
-
- refresh( page );
+ if (element != null) {
+ c = (Collection<Attachment>) element.getObjectValue();
+ log.debug("LIST from cache, " + page.getName() + ", size=" + c.size());
+ return cloneCollection(c);
}
- catch( NeedsRefreshException nre )
- {
- try
- {
- Collection<Attachment> c = refresh( page );
- return cloneCollection(c);
- }
- catch( Exception ex )
- {
- // Is a catch-all, because cache will get confused if
- // we let this one go.
- log.warn("Provider failed, returning cached content",ex);
-
- m_cache.cancelUpdate(page.getName());
-
- return (Collection)nre.getCacheContent();
- }
- }
+ log.debug("list NOT in cache, " + page.getName());
- return new ArrayList();
+ return refresh(page);
}
private <T> Collection<T> cloneCollection( Collection<T> c )
@@ -225,31 +200,32 @@ public class CachingAttachmentProvider
/**
* {@inheritDoc}
*/
- public List listAllChanged( Date timestamp )
- throws ProviderException
- {
+ public List listAllChanged(Date timestamp) throws ProviderException {
List all = null;
//
// we do a one-time build up of the cache, after this the cache is updated for every attachment add/delete
- if (m_gotall == false)
- {
+ if (m_gotall == false) {
all = m_provider.listAllChanged(timestamp);
// Put all pages in the cache :
- synchronized (this)
- {
- for (Iterator i = all.iterator(); i.hasNext();)
- {
+ synchronized (this) {
+ for (Iterator i = all.iterator(); i.hasNext(); ) {
Attachment att = (Attachment) i.next();
- m_attCache.putInCache(att.getName(), att);
+ m_attCache.put(new Element(att.getName(), att));
}
m_gotall = true;
}
- }
- else
- {
- all = m_allCollector.getAllItems();
+ } else {
+ List<String> keys = m_attCache.getKeysWithExpiryCheck();
+ all = new ArrayList();
+ for (String key : keys) {
+ Element element = m_attCache.get(key);
+ Object cachedAttachment = element.getObjectValue();
+ if (cachedAttachment != null) {
+ all.add((Attachment) cachedAttachment);
+ }
+ }
}
return all;
@@ -281,13 +257,10 @@ public class CachingAttachmentProvider
*
* @return The newly fetched object from the provider.
*/
- @SuppressWarnings("unchecked")
- private Collection<Attachment> refresh( WikiPage page )
- throws ProviderException
+ private Collection<Attachment> refresh( WikiPage page ) throws ProviderException
{
- m_cacheMisses++;
Collection<Attachment> c = m_provider.listAttachments( page );
- m_cache.putInCache( page.getName(), c );
+ m_cache.put(new Element(page.getName(), c));
return c;
}
@@ -295,67 +268,33 @@ public class CachingAttachmentProvider
/**
* {@inheritDoc}
*/
- public Attachment getAttachmentInfo( WikiPage page, String name, int version )
- throws ProviderException
- {
- if( log.isDebugEnabled() )
- {
- log.debug("Getting attachments for "+page+", name="+name+", version="+version);
+ public Attachment getAttachmentInfo(WikiPage page, String name, int version) throws ProviderException {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting attachments for " + page + ", name=" + name + ", version=" + version);
}
//
// We don't cache previous versions
//
- if( version != WikiProvider.LATEST_VERSION )
- {
+ if (version != WikiProvider.LATEST_VERSION) {
log.debug("...we don't cache old versions");
- return m_provider.getAttachmentInfo( page, name, version );
+ return m_provider.getAttachmentInfo(page, name, version);
}
- try
- {
- Collection c = (Collection)m_cache.getFromCache( page.getName(), m_refreshPeriod );
-
- if( c == null )
- {
- log.debug("...wasn't in the cache");
- c = refresh( page );
-
- if( c == null ) return null; // No such attachment
- }
- else
- {
- log.debug("...FOUND in the cache");
- m_cacheHits++;
- }
-
- return findAttachmentFromCollection( c, name );
-
- }
- catch( NeedsRefreshException nre )
- {
- log.debug("...needs refresh");
- Collection c = null;
-
- try
- {
- c = refresh( page );
- }
- catch( Exception ex )
- {
- log.warn("Provider failed, returning cached content",ex);
+ Collection<Attachment> c = null;
+ Element element = m_cache.get(page.getName());
- m_cache.cancelUpdate( page.getName() );
- c = (Collection)nre.getCacheContent();
- }
+ if (element == null) {
+ log.debug("...wasn't in the cache");
+ c = refresh(page);
- if( c != null )
- {
- return findAttachmentFromCollection( c, name );
- }
+ if (c == null) return null; // No such attachment
+ } else {
+ log.debug("...FOUND in the cache");
+ c = (Collection<Attachment>) element.getObjectValue();
}
- return null;
+ return findAttachmentFromCollection(c, name);
}
/**
@@ -369,33 +308,34 @@ public class CachingAttachmentProvider
/**
* {@inheritDoc}
*/
- public void deleteVersion( Attachment att )
- throws ProviderException
+ public void deleteVersion( Attachment att ) throws ProviderException
{
// This isn't strictly speaking correct, but it does not really matter
- m_cache.removeEntry( att.getParentName() );
+ m_cache.remove(att.getParentName());
m_provider.deleteVersion( att );
}
/**
* {@inheritDoc}
*/
- public void deleteAttachment( Attachment att )
- throws ProviderException
+ public void deleteAttachment( Attachment att ) throws ProviderException
{
- m_cache.removeEntry( att.getParentName() );
- m_attCache.removeEntry( att.getName() );
+ m_cache.remove(att.getParentName());
+ m_attCache.remove(att.getName());
m_provider.deleteAttachment( att );
}
+
/**
- * {@inheritDoc}
+ * Gets the provider class name, and cache statistics (misscount and,hitcount of the attachment cache).
+ *
+ * @return A plain string with all the above mentioned values.
*/
public synchronized String getProviderInfo()
- {
+ {
return "Real provider: "+m_provider.getClass().getName()+
- ". Cache misses: "+m_cacheMisses+
- ". Cache hits: "+m_cacheHits;
+ ". Cache misses: "+m_cacheMisses+
+ ". Cache hits: "+m_cacheHits;
}
/**
@@ -411,12 +351,11 @@ public class CachingAttachmentProvider
/**
* {@inheritDoc}
*/
- public void moveAttachmentsForPage( String oldParent, String newParent )
- throws ProviderException
+ public void moveAttachmentsForPage( String oldParent, String newParent ) throws ProviderException
{
m_provider.moveAttachmentsForPage(oldParent, newParent);
- m_cache.removeEntry( newParent );
- m_cache.removeEntry( oldParent );
+ m_cache.remove(newParent);
+ m_cache.remove(oldParent);
//
// This is a kludge to make sure that the pages are removed
@@ -424,109 +363,14 @@ public class CachingAttachmentProvider
//
String checkName = oldParent + "/";
- Collection<String> names = cloneCollection( m_allCollector.m_allItems.keySet() );
+ Collection<String> names = m_cache.getKeysWithExpiryCheck();
for( String name : names )
{
if( name.startsWith( checkName ) )
{
- m_attCache.removeEntry( name );
- }
- }
- }
-
- /**
- * Keep a list of all Attachments in the OSCache (OSCache does not provide
- * something like that) Idea copied from CacheItemCollector The cache is used to
- * speed up the getRecentChanges function
- *
- * @since 2.5
- */
- private static class CachedAttachmentCollector implements CacheEntryEventListener
- {
- private static final Logger log = Logger.getLogger( CachedAttachmentCollector.class );
-
- private Map<String, Attachment> m_allItems = new HashMap<String, Attachment>();
-
- /**
- * Returns a clone of the set - you cannot manipulate this.
- *
- * @return A list of all items.
- */
- public List<Attachment> getAllItems()
- {
- List<Attachment> ret = new LinkedList<Attachment>();
- ret.addAll( m_allItems.values() );
- log.info( "returning " + ret.size() + " attachments" );
- return ret;
- }
-
- public void cacheEntryRemoved( CacheEntryEvent aEvent )
- {
- if( aEvent != null )
- {
- if( log.isDebugEnabled() )
- {
- log.debug( "attachment cache entry removed: " + aEvent.getKey() );
- }
-
- CacheEntry e = aEvent.getEntry();
-
- if( e != null )
- {
- Attachment item = (Attachment) e.getContent();
-
- if( item != null )
- {
- m_allItems.remove( item.getName() );
- }
- }
+ m_attCache.remove(name);
}
}
-
- public void cacheEntryUpdated( CacheEntryEvent aEvent )
- {
- if( log.isDebugEnabled() )
- {
- log.debug( "attachment cache entry updated: " + aEvent.getKey() );
- }
-
- Attachment item = (Attachment) aEvent.getEntry().getContent();
-
- if( item != null )
- {
- // Item added or replaced.
- m_allItems.put( item.getName(), item );
- }
- else
- {
- m_allItems.remove( aEvent.getKey() );
- }
- }
-
- public void cacheEntryAdded( CacheEntryEvent aEvent )
- {
- cacheEntryUpdated( aEvent );
- }
-
- public void cachePatternFlushed( CachePatternEvent aEvent )
- {
- // do nothing
- }
-
- public void cacheGroupFlushed( CacheGroupEvent aEvent )
- {
- // do nothing
- }
-
- public void cacheFlushed( CachewideEvent aEvent )
- {
- // do nothing
- }
-
- public void cacheEntryFlushed( CacheEntryEvent aEvent )
- {
- cacheEntryRemoved( aEvent );
- }
}
-}
+}
\ No newline at end of file
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingProvider.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingProvider.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingProvider.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingProvider.java Tue Sep 3 17:42:53 2013
@@ -21,6 +21,9 @@ package org.apache.wiki.providers;
import java.io.IOException;
import java.util.*;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.CacheManager;
import org.apache.log4j.Logger;
import org.apache.wiki.*;
import org.apache.wiki.parser.MarkupParser;
@@ -28,9 +31,6 @@ import org.apache.wiki.render.RenderingM
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.TextUtil;
-import com.opensymphony.oscache.base.Cache;
-import com.opensymphony.oscache.base.NeedsRefreshException;
-import com.opensymphony.oscache.base.events.*;
/**
* Provides a caching page provider. This class rests on top of a
@@ -38,16 +38,14 @@ import com.opensymphony.oscache.base.eve
* if the cache copy of the page text has expired, we fetch it from
* the provider.
* <p>
- * This class also detects if someone has modified the page
- * externally, not through JSPWiki routines, and throws the proper
- * RepositoryModifiedException.
+ * This class does not detect if someone has modified the page
+ * externally, not through JSPWiki routines.
* <p>
* Heavily based on ideas by Chris Brooking.
* <p>
- * Since 2.1.52 uses the OSCache library from OpenSymphony.
+ * Since 2.10 uses the Ehcache library.
*
* @since 1.6.4
- * @see RepositoryModifiedException
*/
// FIXME: Synchronization is a bit inconsistent in places.
// FIXME: A part of the stuff is now redundant, since we could easily use the text cache
@@ -58,15 +56,23 @@ public class CachingProvider
{
private static final Logger log = Logger.getLogger(CachingProvider.class);
+ private CacheManager m_cacheManager = CacheManager.getInstance();
+
private WikiPageProvider m_provider;
// FIXME: Find another way to the search engine to use instead of from WikiEngine?
private WikiEngine m_engine;
- private Cache m_cache;
- private Cache m_negCache; // Cache for holding non-existing pages
+ private Cache m_cache;
+ /** Name of the regular page cache. */
+ public static final String CACHE_NAME = "jspwiki.pageCache";
private Cache m_textCache;
+ /** Name of the page text cache. */
+ public static final String TEXTCACHE_NAME = "jspwiki.pageTextCache";
+
private Cache m_historyCache;
+ /** Name of the page history cache. */
+ public static final String HISTORYCACHE_NAME = "jspwiki.pageHistoryCache";
private long m_cacheMisses = 0;
private long m_cacheHits = 0;
@@ -74,11 +80,8 @@ public class CachingProvider
private long m_historyCacheMisses = 0;
private long m_historyCacheHits = 0;
- private int m_expiryPeriod = 30;
-
/**
- * This can be very long, as normally all modifications are noticed in an earlier
- * stage.
+ * This can be very long, as normally all modifications are noticed in an earlier stage.
*/
private int m_pageContentExpiryPeriod = 24*60*60;
@@ -86,80 +89,45 @@ public class CachingProvider
private boolean m_gotall = false;
- private CacheItemCollector m_allCollector = new CacheItemCollector();
-
- /**
- * Defines, in seconds, the amount of time a text will live in the cache
- * at most before requiring a refresh.
- */
-
- public static final String PROP_CACHECHECKINTERVAL = "jspwiki.cachingProvider.cacheCheckInterval";
-
- /**
- * The capacity of the cache.
- */
- public static final String PROP_CACHECAPACITY = "jspwiki.cachingProvider.capacity";
-
- private static final int DEFAULT_CACHECAPACITY = 1000; // Good most wikis
-
- private static final String OSCACHE_ALGORITHM = "com.opensymphony.oscache.base.algorithm.LRUCache";
+ /** The capacity of the caches, if you want something else, tweak ehcache.xml. */
+ public static final int DEFAULT_CACHECAPACITY = 1000; // Good most wikis
/**
* {@inheritDoc}
*/
public void initialize( WikiEngine engine, Properties properties )
- throws NoRequiredPropertyException,
- IOException
- {
+ throws NoRequiredPropertyException, IOException {
log.debug("Initing CachingProvider");
// engine is used for getting the search engine
m_engine = engine;
- //
- // Cache consistency checks
- //
- m_expiryPeriod = TextUtil.getIntegerProperty( properties,
- PROP_CACHECHECKINTERVAL,
- m_expiryPeriod );
-
- log.debug("Cache expiry period is "+m_expiryPeriod+" s");
-
- //
- // Text cache capacity
- //
- int capacity = TextUtil.getIntegerProperty( properties,
- PROP_CACHECAPACITY,
- DEFAULT_CACHECAPACITY );
-
- log.debug("Cache capacity "+capacity+" pages.");
+ if (m_cacheManager.cacheExists(CACHE_NAME)) {
+ m_cache = m_cacheManager.getCache(CACHE_NAME);
+ } else {
+ log.info("cache with name " + CACHE_NAME + " not found in ehcache.xml, creating it with defaults.");
+ m_cache = new Cache(CACHE_NAME, DEFAULT_CACHECAPACITY, false, false, m_pageContentExpiryPeriod, m_pageContentExpiryPeriod);
+ m_cacheManager.addCache(m_cache);
+ }
- m_cache = new Cache( true, false, false );
+ if (m_cacheManager.cacheExists(TEXTCACHE_NAME)) {
+ m_textCache= m_cacheManager.getCache(TEXTCACHE_NAME);
+ } else {
+ log.info("cache with name " + TEXTCACHE_NAME + " not found in ehcache.xml, creating it with defaults.");
+ m_textCache = new Cache(TEXTCACHE_NAME, DEFAULT_CACHECAPACITY, false, false, m_pageContentExpiryPeriod, m_pageContentExpiryPeriod);
+ m_cacheManager.addCache(m_textCache);
+ }
- //
- // OSCache documentation sucks big time. The clazz-parameter is completely
- // undefined; I had to read the source code to figure out that you need
- // to declare what type of a listener you are adding by sending the type
- // of the interface.
- //
- m_cache.addCacheEventListener( m_allCollector, CacheEntryEventListener.class );
+ if (m_cacheManager.cacheExists(HISTORYCACHE_NAME)) {
+ m_historyCache= m_cacheManager.getCache(HISTORYCACHE_NAME);
+ } else {
+ log.info("cache with name " + HISTORYCACHE_NAME + " not found in ehcache.xml, creating it with defaults.");
+ m_historyCache = new Cache(HISTORYCACHE_NAME, DEFAULT_CACHECAPACITY, false, false, m_pageContentExpiryPeriod, m_pageContentExpiryPeriod);
+ m_cacheManager.addCache(m_historyCache);
+ }
//
- // FIXME: There's an interesting issue here... It would probably be
- // possible to DOS a JSPWiki instance by bombarding it with names that
- // do not exist, as they would fill the negcache. Will need to
- // think about this some more...
- //
- m_negCache = new Cache( true, false, false );
-
- m_textCache = new Cache( true, false, false,
- false,
- OSCACHE_ALGORITHM,
- capacity );
-
- m_historyCache = new Cache( true, false, false, false,
- OSCACHE_ALGORITHM,
- capacity );
+// m_cache.getCacheEventNotificationService().registerListener(new CacheItemCollector());
//
// Find and initialize real provider.
@@ -169,8 +137,7 @@ public class CachingProvider
try
{
- Class providerclass = ClassUtil.findClass( "org.apache.wiki.providers",
- classname );
+ Class providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
m_provider = (WikiPageProvider)providerclass.newInstance();
@@ -195,122 +162,25 @@ public class CachingProvider
}
-
-
- private WikiPage getPageInfoFromCache( String name )
- throws ProviderException
- {
- boolean wasUpdated = false;
+ private WikiPage getPageInfoFromCache(String name) throws ProviderException {
// Sanity check; seems to occur sometimes
- if( name == null ) return null;
-
- try
- {
- WikiPage item = (WikiPage)m_cache.getFromCache( name, m_expiryPeriod );
-
- wasUpdated = true;
-
- if( item != null )
- return item;
-
- return null;
- }
- catch( NeedsRefreshException e )
- {
- WikiPage cached = (WikiPage)e.getCacheContent();
-
- // int version = (cached != null) ? cached.getVersion() : WikiPageProvider.LATEST_VERSION;
-
- WikiPage refreshed;
-
- //
- // Just be careful that we don't accidentally leave the cache in a
- // hung state
- //
-
- refreshed = m_provider.getPageInfo( name, WikiPageProvider.LATEST_VERSION );
-
- if( refreshed == null && cached != null )
- {
- // Page has been removed evilly by a goon from outer space
-
- log.debug("Page "+name+" has been removed externally.");
-
- m_cache.putInCache( name, null );
- m_textCache.putInCache( name, null );
- m_historyCache.putInCache( name, null );
- // We cache a page miss
- m_negCache.putInCache( name, name );
- wasUpdated = true;
-
- throw new RepositoryModifiedException( "Removed: "+name, name );
- }
- else if( cached == null )
- {
- // The page did not exist in the first place
-
- if( refreshed != null )
- {
- // We must now add it
- m_cache.putInCache( name, refreshed );
- // Requests for this page are now no longer denied
- m_negCache.putInCache( name, null );
- wasUpdated = true;
-
- throw new RepositoryModifiedException( "Added: "+name, name );
- }
-
- // Cache page miss
- m_negCache.putInCache( name, name );
- }
- else if( refreshed != null && cached.getVersion() != refreshed.getVersion() )
- {
- // The newest version has been deleted, but older versions still remain
- log.debug("Page "+cached.getName()+" newest version deleted, reloading...");
-
- m_cache.putInCache( name, refreshed );
- // Requests for this page are now no longer denied
- m_negCache.removeEntry( name );
-
- m_textCache.removeEntry( name );
- m_historyCache.removeEntry( name );
- wasUpdated = true;
+ if (name == null) return null;
+ Element cacheElement = m_cache.get(name);
+ if (cacheElement == null) {
+ WikiPage refreshed = m_provider.getPageInfo(name, WikiPageProvider.LATEST_VERSION);
+ if (refreshed != null) {
+ m_cache.put(new Element(name, refreshed));
return refreshed;
+ } else {
+ // page does not exist anywhere
+ return null;
}
- else if( refreshed != null && Math.abs(refreshed.getLastModified().getTime()-cached.getLastModified().getTime()) > 1000L )
- {
- // Yes, the page has been modified externally and nobody told us
-
- log.info("Page "+cached.getName()+" changed, reloading...");
-
- m_cache.putInCache( name, refreshed );
- // Requests for this page are now no longer denied
- m_negCache.removeEntry( name );
- m_textCache.removeEntry( name );
- m_historyCache.removeEntry( name );
- wasUpdated = true;
-
- throw new RepositoryModifiedException( "Modified: "+name, name );
- }
- else
- {
- // Refresh the cache by putting the same object back
- m_cache.putInCache( name, cached );
- // Requests for this page are now no longer denied
- m_negCache.putInCache( name, null );
- wasUpdated = true;
- }
-
- return cached;
- }
- finally
- {
- if( !wasUpdated )
- m_cache.cancelUpdate(name);
}
+ return (WikiPage) cacheElement.getObjectValue();
}
+
/**
* {@inheritDoc}
*/
@@ -318,43 +188,12 @@ public class CachingProvider
{
if( pageName == null ) return false;
- //
- // First, check the negative cache if we've seen it before
- //
- try
- {
- String isNonExistant = (String) m_negCache.getFromCache( pageName, m_expiryPeriod );
-
- if( isNonExistant != null ) return false; // No such page
- }
- catch( NeedsRefreshException e )
- {
- m_negCache.cancelUpdate(pageName);
- }
-
WikiPage p = null;
try
{
p = getPageInfoFromCache( pageName );
}
- catch( RepositoryModifiedException e )
- {
- // The repository was modified, we need to check now if the page was removed or
- // added.
- // TODO: This information would be available in the exception, but we would
- // need to subclass.
-
- try
- {
- p = getPageInfoFromCache( pageName );
- }
- catch( Exception ex )
- {
- // This should not happen
- return false;
- }
- }
catch( ProviderException e )
{
log.info("Provider failed while trying to check if page exists: "+pageName);
@@ -391,42 +230,12 @@ public class CachingProvider
{
if( pageName == null ) return false;
- //
- // First, check the negative cache if we've seen it before
- //
- try
- {
- String isNonExistant = (String) m_negCache.getFromCache( pageName, m_expiryPeriod );
-
- if( isNonExistant != null ) return false; // No such page
- }
- catch( NeedsRefreshException e )
- {
- m_negCache.cancelUpdate(pageName);
- }
-
WikiPage p = null;
try
{
p = getPageInfoFromCache( pageName );
}
- catch( RepositoryModifiedException e )
- {
- // The repository was modified, we need to check now if the page was removed or
- // added.
- // TODO: This information would be available in the exception, but we would
- // need to subclass.
-
- try
- {
- p = getPageInfoFromCache( pageName );
- }
- catch( Exception ex )
- {
- return false; // This should not happen
- }
- }
catch( ProviderException e )
{
log.info("Provider failed while trying to check if page exists: "+pageName);
@@ -447,10 +256,6 @@ public class CachingProvider
// If we have a list of all pages in memory, then any page
// not in the cache must be non-existent.
//
- // FIXME: There's a problem here; if someone modifies the
- // repository by adding a page outside JSPWiki,
- // we won't notice it.
-
if( m_gotall )
{
return false;
@@ -470,7 +275,6 @@ public class CachingProvider
/**
* {@inheritDoc}
- * @throws RepositoryModifiedException If the page has been externally modified.
*/
public String getPageText( String pageName, int version )
throws ProviderException
@@ -504,131 +308,78 @@ public class CachingProvider
}
- /**
- * @throws RepositoryModifiedException If the page has been externally modified.
- */
- private String getTextFromCache( String pageName )
- throws ProviderException
- {
- String text;
- boolean wasUpdated = false;
-
- if( pageName == null ) return null;
-
- WikiPage page = getPageInfoFromCache( pageName );
+ private String getTextFromCache(String pageName) throws ProviderException {
+ String text = null;
- try
- {
- text = (String)m_textCache.getFromCache( pageName,
- m_pageContentExpiryPeriod );
- wasUpdated = true;
+ if (pageName == null) return null;
- if( text == null )
- {
- if( page != null )
- {
- text = m_provider.getPageText( pageName, WikiPageProvider.LATEST_VERSION );
+ WikiPage page = getPageInfoFromCache(pageName);
- m_textCache.putInCache( pageName, text );
+ Element cacheElement = m_textCache.get(pageName);
- m_cacheMisses++;
- }
- else
- {
- return null;
- }
- }
- else
- {
- m_cacheHits++;
- }
- }
- catch( NeedsRefreshException e )
- {
- if( pageExists(pageName) )
- {
- text = m_provider.getPageText( pageName, WikiPageProvider.LATEST_VERSION );
-
- m_textCache.putInCache( pageName, text );
- wasUpdated = true;
-
- m_cacheMisses++;
- }
- else
- {
- m_textCache.putInCache( pageName, null );
- wasUpdated = true;
- return null; // No page exists
- }
+ if (cacheElement != null) {
+ m_cacheHits++;
+ return (String) cacheElement.getObjectValue();
}
- finally
- {
- if( !wasUpdated )
- m_textCache.cancelUpdate(pageName);
+ if (pageExists(pageName)) {
+ text = m_provider.getPageText(pageName, WikiPageProvider.LATEST_VERSION);
+ m_textCache.put(new Element(pageName, text));
+ m_cacheMisses++;
+ return text;
}
-
- return text;
+ //page not found (not in cache, not by real provider
+ return null;
}
/**
* {@inheritDoc}
*/
- public void putPageText( WikiPage page, String text )
- throws ProviderException
- {
- synchronized(this)
- {
- m_provider.putPageText( page, text );
+ public void putPageText(WikiPage page, String text) throws ProviderException {
+ synchronized (this) {
+ m_provider.putPageText(page, text);
- page.setLastModified( new Date() );
+ page.setLastModified(new Date());
// Refresh caches properly
- m_cache.removeEntry( page.getName() );
- m_textCache.removeEntry( page.getName() );
- m_historyCache.removeEntry( page.getName() );
- m_negCache.removeEntry( page.getName() );
+ m_cache.remove(page.getName());
+ m_textCache.remove(page.getName());
+ m_historyCache.remove(page.getName());
- // Refresh caches
- try
- {
- getPageInfoFromCache( page.getName() );
- }
- catch(RepositoryModifiedException e) {} // Expected
+ getPageInfoFromCache(page.getName());
}
}
/**
* {@inheritDoc}
*/
- public Collection getAllPages()
- throws ProviderException
- {
+ public Collection getAllPages() throws ProviderException {
Collection all;
- if( m_gotall == false )
- {
+ if (m_gotall == false) {
all = m_provider.getAllPages();
// Make sure that all pages are in the cache.
- synchronized(this)
- {
- for( Iterator i = all.iterator(); i.hasNext(); )
- {
+ synchronized (this) {
+ for (Iterator i = all.iterator(); i.hasNext(); ) {
WikiPage p = (WikiPage) i.next();
- m_cache.putInCache( p.getName(), p );
- // Requests for this page are now no longer denied
- m_negCache.putInCache( p.getName(), null );
+ m_cache.put(new Element(p.getName(), p));
}
m_gotall = true;
}
- }
- else
- {
- all = m_allCollector.getAllItems();
+ } else {
+ List<String> keys = m_cache.getKeysWithExpiryCheck();
+ all = new TreeSet<WikiPage>();
+ for (String key : keys) {
+ Element element = m_cache.get(key);
+ Object cachedPage = element.getObjectValue();
+ if (cachedPage != null) {
+ all.add((WikiPage) cachedPage);
+ }
+ }
}
return all;
@@ -695,16 +446,14 @@ public class CachingProvider
/**
* {@inheritDoc}
*/
- public WikiPage getPageInfo( String pageName, int version )
- throws ProviderException
+ public WikiPage getPageInfo( String pageName, int version ) throws ProviderException
{
WikiPage page = null;
WikiPage cached = getPageInfoFromCache( pageName );
int latestcached = (cached != null) ? cached.getVersion() : Integer.MIN_VALUE;
- if( version == WikiPageProvider.LATEST_VERSION ||
- version == latestcached )
+ if( version == WikiPageProvider.LATEST_VERSION || version == latestcached )
{
if( cached == null )
{
@@ -712,9 +461,7 @@ public class CachingProvider
if( data != null )
{
- m_cache.putInCache( pageName, data );
- // Requests for this page are now no longer denied
- m_negCache.putInCache( pageName, null );
+ m_cache.put(new Element(pageName, data));
}
page = data;
}
@@ -738,51 +485,36 @@ public class CachingProvider
/**
* {@inheritDoc}
*/
- public List getVersionHistory( String pageName )
- throws ProviderException
- {
+ public List getVersionHistory(String pageName) throws ProviderException {
List history = null;
- boolean wasUpdated = false;
- if( pageName == null ) return null;
- try
- {
- history = (List)m_historyCache.getFromCache( pageName,
- m_expiryPeriod );
+ if (pageName == null) return null;
+ Element element = m_historyCache.get(pageName);
- log.debug("History cache hit for page "+pageName);
+ if (element != null) {
m_historyCacheHits++;
- wasUpdated = true;
- }
- catch( NeedsRefreshException e )
- {
- history = m_provider.getVersionHistory( pageName );
-
- m_historyCache.putInCache( pageName, history );
-
- log.debug("History cache miss for page "+pageName);
+ history = (List) element.getObjectValue();
+ } else {
+ history = m_provider.getVersionHistory(pageName);
+ m_historyCache.put( new Element( pageName, history ));
m_historyCacheMisses++;
- wasUpdated = true;
- }
- finally
- {
- if( !wasUpdated ) m_historyCache.cancelUpdate( pageName );
}
return history;
}
/**
- * {@inheritDoc}
+ * Gets the provider class name, and cache statistics (misscount and hitcount of page cache and history cache).
+ *
+ * @return A plain string with all the above mentioned values.
*/
public synchronized String getProviderInfo()
{
return "Real provider: "+m_provider.getClass().getName()+
- ". Cache misses: "+m_cacheMisses+
- ". Cache hits: "+m_cacheHits+
- ". History cache hits: "+m_historyCacheHits+
- ". History cache misses: "+m_historyCacheMisses+
- ". Cache consistency checks: "+m_expiryPeriod+"s";
+ ". Cache misses: "+m_cacheMisses+
+ ". Cache hits: "+m_cacheHits+
+ ". History cache hits: "+m_historyCacheHits+
+ ". History cache misses: "+m_historyCacheMisses;
}
/**
@@ -807,12 +539,12 @@ public class CachingProvider
if( version == WikiPageProvider.LATEST_VERSION ||
version == latestcached )
{
- m_cache.removeEntry( pageName );
- m_textCache.removeEntry( pageName );
+ m_cache.remove(pageName);
+ m_textCache.remove(pageName);
}
m_provider.deleteVersion( pageName, version );
- m_historyCache.removeEntry( pageName );
+ m_historyCache.remove(pageName);
}
}
@@ -827,42 +559,28 @@ public class CachingProvider
//
synchronized(this)
{
- m_cache.putInCache( pageName, null );
- m_textCache.putInCache( pageName, null );
- m_historyCache.putInCache( pageName, null );
- m_negCache.putInCache( pageName, pageName );
- m_provider.deletePage( pageName );
+ m_cache.put(new Element(pageName, null));
+ m_textCache.put(new Element( pageName, null ));
+ m_historyCache.put(new Element(pageName, null));
+ m_provider.deletePage(pageName);
}
}
/**
* {@inheritDoc}
*/
- public void movePage( String from,
- String to )
- throws ProviderException
- {
- m_provider.movePage( from, to );
+ public void movePage(String from, String to) throws ProviderException {
+ m_provider.movePage(from, to);
- synchronized(this)
- {
- // Clear any cached version of the old page
- log.debug("Removing from page "+from+" from cache");
-// m_cache.removeEntry( from );
- m_cache.putInCache( from, null );
- m_textCache.putInCache( from, null );
- m_historyCache.putInCache( from, null );
- m_negCache.putInCache( from, from );
- // Clear the cache for the to page, if that page already exists
- //if ( m_cache.get( to ) != null )
- //{
- log.debug("Removing to page "+to+" from cache");
-// m_cache.removeEntry( to );
- m_cache.putInCache( to, null );
- m_textCache.putInCache( to, null );
- m_historyCache.putInCache( to, null );
- m_negCache.putInCache( to, to );
- //}
+ synchronized (this) {
+ // Clear any cached version of the old page and new page
+ m_cache.remove(from);
+ m_textCache.remove(from);
+ m_historyCache.remove(from);
+ log.debug("Removing to page " + to + " from cache");
+ m_cache.remove(to);
+ m_textCache.remove(to);
+ m_historyCache.remove(to);
}
}
@@ -876,84 +594,4 @@ public class CachingProvider
return m_provider;
}
- /**
- * This is a simple class that keeps a list of all WikiPages that
- * we have in memory. Because the OSCache cannot give us a list
- * of all pages currently in cache, we'll have to check this
- * ourselves.
- *
- *
- * @since 2.4
- */
- private static class CacheItemCollector
- implements CacheEntryEventListener
- {
- private Map<String, WikiPage> m_allItems = new Hashtable<String, WikiPage>();
-
- /**
- * Returns a clone of the set - you cannot manipulate this.
- *
- * @return A Set of WikiPage objects.
- */
- public Set getAllItems()
- {
- Set<WikiPage> ret = new TreeSet<WikiPage>();
- ret.addAll(m_allItems.values());
-
- return ret;
- }
-
- public void cacheEntryAdded( CacheEntryEvent arg0 )
- {
- cacheEntryUpdated( arg0 );
- }
-
- public void cachePatternFlushed( CachePatternEvent ev )
- {
- }
-
- public void cacheGroupFlushed( CacheGroupEvent ev )
- {
- }
-
- public void cacheFlushed( CachewideEvent ev )
- {
- }
-
- public void cacheEntryFlushed( CacheEntryEvent arg0 )
- {
- cacheEntryRemoved( arg0 );
- }
-
- public void cacheEntryRemoved( CacheEntryEvent arg0 )
- {
- if( arg0.getEntry() != null )
- {
- WikiPage item = (WikiPage) arg0.getEntry().getContent();
-
- if( item != null )
- {
- m_allItems.remove( item.getName() );
- }
- }
- }
-
- public void cacheEntryUpdated( CacheEntryEvent arg0 )
- {
- WikiPage item = (WikiPage) arg0.getEntry().getContent();
-
- if( item != null )
- {
- // Item added or replaced.
- m_allItems.put( item.getName(), item );
- }
- else
- {
- // Removed item
- // FIXME: If the page system is changed during this time, we'll just fail gracefully
-
- m_allItems.remove( arg0.getKey() );
- }
- }
- }
}
Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/render/RenderingManager.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/render/RenderingManager.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/render/RenderingManager.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/render/RenderingManager.java Tue Sep 3 17:42:53 2013
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
@@ -40,8 +43,6 @@ import org.apache.wiki.parser.MarkupPars
import org.apache.wiki.parser.WikiDocument;
import org.apache.wiki.providers.CachingProvider;
import org.apache.wiki.util.TextUtil;
-import com.opensymphony.oscache.base.Cache;
-import com.opensymphony.oscache.base.NeedsRefreshException;
/**
* This class provides a facade towards the differing rendering routines. You should
@@ -49,13 +50,8 @@ import com.opensymphony.oscache.base.Nee
* want the different side effects to occur - such as WikiFilters.
* <p>
* This class also manages a rendering cache, i.e. documents are stored between calls.
- * You may control the size of the cache by using the "jspwiki.renderingManager.cacheSize"
- * parameter in jspwiki.properties. The property value is the number of items that
- * are stored in the cache. By default, the value of this parameter is taken from
- * the "jspwiki.cachingProvider.cacheSize" parameter (i.e. the rendering cache is
- * the same size as the page cache), but you may control them separately.
+ * You may control the cache by tweaking the ehcache.xml file.
* <p>
- * You can turn caching completely off by stating a cacheSize of zero.
*
* @since 2.4
*/
@@ -67,13 +63,11 @@ public class RenderingManager implements
private WikiEngine m_engine;
- /**
- * Parameter value for setting the cache size.
- */
- public static final String PROP_CACHESIZE = "jspwiki.renderingManager.capacity";
+ private CacheManager m_cacheManager = CacheManager.getInstance();
+
+ /** The capacity of the caches, if you want something else, tweak ehcache.xml. */
private static final int DEFAULT_CACHESIZE = 1000;
private static final String VERSION_DELIMITER = "::";
- private static final String OSCACHE_ALGORITHM = "com.opensymphony.oscache.base.algorithm.LRUCache";
private static final String PROP_RENDERER = "jspwiki.renderingManager.renderer";
/** The name of the default renderer. */
@@ -82,11 +76,10 @@ public class RenderingManager implements
/**
* Stores the WikiDocuments that have been cached.
*/
- private Cache m_documentCache;
+ private Cache m_documentCache;
+ /** Name of the regular page cache. */
+ public static final String DOCUMENTCACHE_NAME = "jspwiki.renderingCache";
- /**
- *
- */
private Constructor m_rendererConstructor;
/**
@@ -115,24 +108,13 @@ public class RenderingManager implements
throws WikiException
{
m_engine = engine;
- int cacheSize = TextUtil.getIntegerProperty( properties, PROP_CACHESIZE, -1 );
-
- if( cacheSize == -1 )
- {
- cacheSize = TextUtil.getIntegerProperty( properties,
- CachingProvider.PROP_CACHECAPACITY,
- DEFAULT_CACHESIZE );
- }
- if( cacheSize > 0 )
- {
- m_documentCache = new Cache(true,false,false,false,
- OSCACHE_ALGORITHM,
- cacheSize);
- }
- else
- {
- log.info( "RenderingManager caching is disabled." );
+ if (m_cacheManager.cacheExists(DOCUMENTCACHE_NAME)) {
+ m_documentCache = m_cacheManager.getCache(DOCUMENTCACHE_NAME);
+ } else {
+ log.info("cache with name " + DOCUMENTCACHE_NAME + " not found in ehcache.xml, creating it with defaults.");
+ m_documentCache = new Cache(DOCUMENTCACHE_NAME, DEFAULT_CACHESIZE, false, false, m_cacheExpiryPeriod, m_cacheExpiryPeriod);
+ m_cacheManager.addCache(m_documentCache);
}
String renderImplName = properties.getProperty( PROP_RENDERER );
@@ -189,39 +171,24 @@ public class RenderingManager implements
* @return the rendered wiki document
* @throws IOException If rendering cannot be accomplished
*/
- // FIXME: The cache management policy is not very good: deleted/changed pages
- // should be detected better.
- protected WikiDocument getRenderedDocument( WikiContext context, String pagedata )
- throws IOException
- {
- String pageid = context.getRealPage().getName()+VERSION_DELIMITER+context.getRealPage().getVersion();
-
- boolean wasUpdated = false;
-
- if( m_documentCache != null )
- {
- try
- {
- WikiDocument doc = (WikiDocument) m_documentCache.getFromCache( pageid,
- m_cacheExpiryPeriod );
-
- wasUpdated = true;
+ // FIXME: The cache management policy is not very good: deleted/changed pages should be detected better.
+ protected WikiDocument getRenderedDocument(WikiContext context, String pagedata) throws IOException {
+ String pageid = context.getRealPage().getName() + VERSION_DELIMITER + context.getRealPage().getVersion();
+
+ Element element = m_documentCache.get(pageid);
+ if (element != null) {
+ WikiDocument doc = (WikiDocument) element.getObjectValue();
//
- // This check is needed in case the different filters have actually
- // changed the page data.
+ // This check is needed in case the different filters have actually changed the page data.
// FIXME: Figure out a faster method
- if( pagedata.equals(doc.getPageData()) )
- {
- if( log.isDebugEnabled() ) log.debug("Using cached HTML for page "+pageid );
+ if (pagedata.equals(doc.getPageData())) {
+ if (log.isDebugEnabled()) log.debug("Using cached HTML for page " + pageid);
return doc;
}
+ } else {
+ if (log.isDebugEnabled()) log.debug("Re-rendering and storing " + pageid);
}
- catch( NeedsRefreshException e )
- {
- if( log.isDebugEnabled() ) log.debug("Re-rendering and storing "+pageid );
- }
- }
//
// Refresh the data content
@@ -231,21 +198,13 @@ public class RenderingManager implements
MarkupParser parser = getParser( context, pagedata );
WikiDocument doc = parser.parse();
doc.setPageData( pagedata );
- if( m_documentCache != null )
- {
- m_documentCache.putInCache( pageid, doc );
- wasUpdated = true;
- }
+ m_documentCache.put( new Element(pageid, doc ));
return doc;
}
catch( IOException ex )
{
log.error("Unable to parse",ex);
}
- finally
- {
- if( m_documentCache != null && !wasUpdated ) m_documentCache.cancelUpdate( pageid );
- }
return null;
}
@@ -262,8 +221,7 @@ public class RenderingManager implements
* @return Rendered HTML.
* @throws IOException If the WikiDocument is poorly formed.
*/
- public String getHTML( WikiContext context, WikiDocument doc )
- throws IOException
+ public String getHTML( WikiContext context, WikiDocument doc ) throws IOException
{
WikiRenderer rend = getRenderer( context, doc );
@@ -296,7 +254,7 @@ public class RenderingManager implements
}
/**
- * Convinience method for rendering, using the default parser and renderer. Note that
+ * Convenience method for rendering, using the default parser and renderer. Note that
* you can't use this method to do any arbitrary rendering, as the pagedata MUST
* be the data from the that the WikiContext refers to - this method caches the HTML
* internally, and will return the cached version. If the pagedata is different
@@ -336,12 +294,12 @@ public class RenderingManager implements
if( m_documentCache != null )
{
String pageName = ((WikiPageEvent) event).getPageName();
- m_documentCache.flushPattern( pageName );
+ m_documentCache.remove(pageName);
Collection referringPages = m_engine.getReferenceManager().findReferrers( pageName );
//
- // Flush also those pages that refer to this page (if an nonexistant page
- // appears; we need to flush the HTML that refers to the now-existant page
+ // Flush also those pages that refer to this page (if an nonexistent page
+ // appears; we need to flush the HTML that refers to the now-existent page
//
if( referringPages != null )
{
@@ -350,7 +308,7 @@ public class RenderingManager implements
{
String page = (String) i.next();
if( log.isDebugEnabled() ) log.debug( "Flushing " + page );
- m_documentCache.flushPattern( page );
+ m_documentCache.remove(page);
}
}
}
Modified: jspwiki/trunk/jspwiki-war/src/main/webapp/SisterSites.jsp
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/webapp/SisterSites.jsp?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/webapp/SisterSites.jsp (original)
+++ jspwiki/trunk/jspwiki-war/src/main/webapp/SisterSites.jsp Tue Sep 3 17:42:53 2013
@@ -23,7 +23,6 @@
<%@ page import="org.apache.wiki.preferences.Preferences" %>
<%@ page import="org.apache.wiki.rss.*" %>
<%@ page import="org.apache.wiki.util.*" %>
-<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %>
<%!
Logger log = Logger.getLogger("JSPWiki");
%>
Modified: jspwiki/trunk/jspwiki-war/src/main/webapp/rss.jsp
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/webapp/rss.jsp?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/webapp/rss.jsp (original)
+++ jspwiki/trunk/jspwiki-war/src/main/webapp/rss.jsp Tue Sep 3 17:42:53 2013
@@ -25,16 +25,27 @@
<%@ page import="org.apache.wiki.preferences.Preferences" %>
<%@ page import="org.apache.wiki.rss.*" %>
<%@ page import="org.apache.wiki.util.*" %>
-<%@ page import="com.opensymphony.oscache.base.*" %>
-<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %>
+<%@ page import="net.sf.ehcache.Cache" %>
+<%@ page import="net.sf.ehcache.Element" %>
+<%@ page import="net.sf.ehcache.CacheManager" %>
<%!
- Logger log = Logger.getLogger("JSPWiki");
- Cache m_cache = new Cache( true, false, false, true,
- "com.opensymphony.oscache.base.algorithm.LRUCache", 256 );
+ private Logger log = Logger.getLogger("JSPWiki");
+ private CacheManager m_cacheManager = CacheManager.getInstance();
+ private String cacheName = "jspwiki.rssCache";
+ private Cache m_rssCache;
+ private int m_expiryPeriod = 24*60*60;
+ private int cacheCapacity = 1000;
%>
<%
+ if (m_cacheManager.cacheExists(cacheName)) {
+ m_rssCache = m_cacheManager.getCache(cacheName);
+ } else {
+ log.info("cache with name " + cacheName + " not found in ehcache.xml, creating it with defaults.");
+ m_rssCache = new Cache(cacheName, cacheCapacity, false, false, m_expiryPeriod, m_expiryPeriod);
+ m_cacheManager.addCache(m_rssCache);
+ }
WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
// Create wiki context and check for authorization
WikiContext wikiContext = wiki.createContext( request, "rss" );
@@ -139,22 +150,15 @@
String hashKey = wikipage.getName()+";"+mode+";"+type+";"+latest.getTime();
String rss = "";
-
- try
- {
- rss = (String)m_cache.getFromCache(hashKey);
+
+ Element element = m_rssCache.get(hashKey);
+ if (element != null) {
+ rss = (String) element.getObjectValue();
}
- catch( NeedsRefreshException e )
+ else
{
- try
- {
- rss = wiki.getRSSGenerator().generateFeed( wikiContext, changed, mode, type );
- m_cache.putInCache(hashKey,rss);
- }
- catch( Exception e1 )
- {
- m_cache.cancelUpdate(hashKey);
- }
+ rss = wiki.getRSSGenerator().generateFeed( wikiContext, changed, mode, type );
+ m_rssCache.put(new Element(hashKey,rss));
}
out.println(rss);
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/WikiEngineTest.java Tue Sep 3 17:42:53 2013
@@ -30,6 +30,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
import org.apache.wiki.attachment.Attachment;
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.providers.BasicAttachmentProvider;
@@ -68,11 +69,8 @@ public class WikiEngineTest extends Test
throws Exception
{
props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" );
- // We'll need a shorter-than-default consistency check for
- // the page-changed checks. This will cause additional load
- // to the file system, though.
- props.setProperty( CachingProvider.PROP_CACHECHECKINTERVAL,
- Long.toString(PAGEPROVIDER_RESCAN_PERIOD) );
+
+ CacheManager.getInstance().removalAll();
TestEngine.emptyWorkDir();
m_engine = new TestEngine(props);
@@ -725,118 +723,7 @@ public class WikiEngineTest extends Test
assertEquals( "content1", "", engine.getText(NAME1, 1).trim() );
}
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModificationRefs()
- throws Exception
- {
- ReferenceManager refMgr = m_engine.getReferenceManager();
-
- m_engine.saveText( NAME1, "[Foobar]" );
- m_engine.getText( NAME1 ); // Ensure that page is cached.
-
- Collection c = refMgr.findUncreated();
- assertTrue( "Non-existent reference not detected by ReferenceManager",
- Util.collectionContains( c, "Foobar" ));
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );
-
- assertTrue( "No file!", saved.exists() );
-
- FileWriter out = new FileWriter( saved );
- FileUtil.copyContents( new StringReader("[Puppaa]"), out );
- out.close();
-
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // Wait five seconds for CachingProvider to wake up.
-
- String text = m_engine.getText( NAME1 );
-
- assertEquals( "wrong contents", "[Puppaa]", text );
-
- c = refMgr.findUncreated();
-
- assertTrue( "Non-existent reference after external page change " +
- "not detected by ReferenceManager",
- Util.collectionContains( c, "Puppaa" ));
- }
-
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModificationRefsDeleted()
- throws Exception
- {
- ReferenceManager refMgr = m_engine.getReferenceManager();
-
- m_engine.saveText( NAME1, "[Foobar]" );
- m_engine.getText( NAME1 ); // Ensure that page is cached.
- Collection c = refMgr.findUncreated();
- assertEquals( "uncreated count", 1, c.size() );
- assertEquals( "wrong referenced page", "Foobar", (String)c.iterator().next() );
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );
-
- assertTrue( "No file!", saved.exists() );
-
- saved.delete();
-
- assertFalse( "File not deleted!", saved.exists() );
-
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // Wait five seconds for CachingProvider to catch up.
-
- WikiPage p = m_engine.getPage( NAME1 );
-
- assertNull( "Got page!", p );
-
- String text = m_engine.getText( NAME1 );
-
- assertEquals( "wrong contents", "", text );
-
- c = refMgr.findUncreated();
- assertEquals( "NEW: uncreated count", 0, c.size() );
- }
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModification()
- throws Exception
- {
- m_engine.saveText( NAME1, "Foobar" );
-
- m_engine.getText( NAME1 ); // Ensure that page is cached.
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );
-
- assertTrue( "No file!", saved.exists() );
-
- FileWriter out = new FileWriter( saved );
- FileUtil.copyContents( new StringReader("Puppaa"), out );
- out.close();
-
- // Wait for the caching provider to notice a refresh.
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD );
-
- // Trim - engine.saveText() may append a newline.
- String text = m_engine.getText( NAME1 ).trim();
- assertEquals( "wrong contents", "Puppaa", text );
- }
/**
* Tests BugReadingOfVariableNotWorkingForOlderVersions
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java Tue Sep 3 17:42:53 2013
@@ -21,6 +21,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
import org.apache.wiki.TestEngine;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiPage;
@@ -47,6 +48,10 @@ public class AttachmentManagerTest exten
public void setUp()
throws Exception
{
+ CacheManager m_cacheManager = CacheManager.getInstance();
+ m_cacheManager.clearAll();
+ m_cacheManager.removalAll();
+
m_engine = new TestEngine(props);
m_manager = m_engine.getAttachmentManager();
@@ -336,7 +341,7 @@ public class AttachmentManagerTest exten
m_engine.pageExists( att.getName() ) );
}
- public void testNonexistantPage() throws Exception
+ public void testNonexistentPage() throws Exception
{
try
{
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/content/PageRenamerTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/content/PageRenamerTest.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/content/PageRenamerTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/content/PageRenamerTest.java Tue Sep 3 17:42:53 2013
@@ -25,6 +25,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
import org.apache.wiki.*;
import org.apache.wiki.api.exceptions.WikiException;
import org.apache.wiki.attachment.Attachment;
@@ -40,8 +41,11 @@ public class PageRenamerTest extends Tes
Properties props = TestEngine.getTestProperties();
props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" );
-
+
+ CacheManager.getInstance().removalAll();
+
TestEngine.emptyWorkDir();
+
m_engine = new TestEngine(props);
}
@@ -272,7 +276,7 @@ public class PageRenamerTest extends Tes
{
m_engine.saveText( "TestPage", "hubbub");
m_engine.saveText( "TestPage2", "[TestPage|]" );
-
+
rename( "TestPage", "FooTest" );
WikiPage p = m_engine.getPage( "FooTest" );
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java Tue Sep 3 17:42:53 2013
@@ -33,6 +33,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
import org.apache.wiki.*;
import org.apache.wiki.api.exceptions.WikiException;
import org.apache.wiki.attachment.Attachment;
@@ -59,6 +60,8 @@ public class JSPWikiMarkupParserTest ext
public void setUp()
throws Exception
{
+ CacheManager.getInstance().removalAll();
+
props.setProperty( "jspwiki.translatorReader.matchEnglishPlurals", "true" );
testEngine = new TestEngine( props );
}
Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java?rev=1519765&r1=1519764&r2=1519765&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java Tue Sep 3 17:42:53 2013
@@ -24,6 +24,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import net.sf.ehcache.CacheManager;
import org.apache.wiki.TestEngine;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiPage;
@@ -47,6 +48,7 @@ public class PageViewPluginTest extends
public void setUp() throws Exception
{
+ CacheManager.getInstance().removalAll();
testEngine = new TestEngine( props );
// create pages that should be counted