You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/10/07 20:40:49 UTC
svn commit: r1180142 -
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
Author: hlship
Date: Fri Oct 7 18:40:48 2011
New Revision: 1180142
URL: http://svn.apache.org/viewvc?rev=1180142&view=rev
Log:
TAP5-1508: Use SoftReferences for cached resources (gzipped or uncompressed)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java?rev=1180142&r1=1180141&r2=1180142&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java Fri Oct 7 18:40:48 2011
@@ -14,9 +14,6 @@
package org.apache.tapestry5.internal.services.assets;
-import java.io.IOException;
-import java.util.Map;
-
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.services.InvalidationListener;
@@ -24,6 +21,10 @@ import org.apache.tapestry5.services.ass
import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
import org.apache.tapestry5.services.assets.StreamableResourceSource;
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.util.Map;
+
/**
* An interceptor for the {@link StreamableResourceSource} service that handles caching of content.
*/
@@ -33,7 +34,7 @@ public class SRSCachingInterceptor imple
private final StreamableResourceSource delegate;
- private final Map<Resource, StreamableResource> cache = CollectionFactory.newConcurrentMap();
+ private final Map<Resource, SoftReference<StreamableResource>> cache = CollectionFactory.newConcurrentMap();
public SRSCachingInterceptor(ResourceChangeTracker tracker, StreamableResourceSource delegate)
{
@@ -45,9 +46,13 @@ public class SRSCachingInterceptor imple
throws IOException
{
if (processing == StreamableResourceProcessing.FOR_AGGREGATION)
+ {
return delegate.getStreamableResource(baseResource, processing);
+ }
+
+ SoftReference<StreamableResource> ref = cache.get(baseResource);
- StreamableResource result = cache.get(baseResource);
+ StreamableResource result = ref == null ? null : ref.get();
if (result == null)
{
@@ -57,7 +62,7 @@ public class SRSCachingInterceptor imple
{
tracker.trackResource(baseResource);
- cache.put(baseResource, result);
+ cache.put(baseResource, new SoftReference<StreamableResource>(result));
}
}
@@ -66,7 +71,7 @@ public class SRSCachingInterceptor imple
/**
* Always returns true; a subclass may extend this to only cache the resource in some circumstances.
- *
+ *
* @param resource
* @return true to cache the resource
*/