Author: etnu
Date: Fri Jul 4 23:13:48 2008
New Revision: 674156
URL: http://svn.apache.org/viewvc?rev=674156&view=rev
Log:
Added injectable default & negative caching ttls for HTTP responses. This had
to be done as a static injection since there is nothing that produces
HttpResponse objects other than fetchers.
Modified:
incubator/shindig/trunk/java/gadgets/conf/gadgets.properties
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
Modified: incubator/shindig/trunk/java/gadgets/conf/gadgets.properties
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/conf/gadgets.properties?rev=674156&r1=674155&r2=674156&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/conf/gadgets.properties (original)
+++ incubator/shindig/trunk/java/gadgets/conf/gadgets.properties Fri Jul 4
23:13:48 2008
@@ -17,3 +17,5 @@
gadget-spec.cache.maxTTL=600000
message-bundle.cache.minTTL=300000
message-bundle.cache.maxTTL=600000
+http.cache.defaultTtl=3600000
+http.cache.negativeCacheTtl=30000
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=674156&r1=674155&r2=674156&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
Fri Jul 4 23:13:48 2008
@@ -24,6 +24,7 @@
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
import org.apache.shindig.gadgets.http.HttpCache;
import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.http.RemoteContentFetcherFactory;
import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
import org.apache.shindig.gadgets.rewrite.ContentRewriter;
@@ -51,6 +52,7 @@
/** [EMAIL PROTECTED] */
@Override
protected void configure() {
+ System.out.println("Created default injector: " + this);
Names.bindProperties(this.binder(), properties);
bind(ContentRewriter.class).to(DefaultContentRewriter.class);
@@ -76,6 +78,9 @@
bind(ContainerConfig.class);
bind(GadgetFeatureRegistry.class);
bind(GadgetServer.class);
+
+ // We perform static injection on HttpResponse for cache TTLs.
+ requestStaticInjection(HttpResponse.class);
}
public DefaultGuiceModule(Properties properties) {
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java?rev=674156&r1=674155&r2=674156&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
Fri Jul 4 23:13:48 2008
@@ -19,6 +19,8 @@
import org.apache.shindig.common.util.DateUtil;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
@@ -53,13 +55,13 @@
// TTL to use when an error response is fetched. This should be non-zero to
// avoid high rates of requests to bad urls in high-traffic situations.
- public final static long NEGATIVE_CACHE_TTL = 30 * 1000;
+ protected final static long NEGATIVE_CACHE_TTL = 30 * 1000;
/**
* Default TTL for an entry in the cache that does not have any
* cache controlling headers.
*/
- public static final long DEFAULT_TTL = 5L * 60L * 1000L;
+ protected static final long DEFAULT_TTL = 5L * 60L * 1000L;
public static final String DEFAULT_ENCODING = "UTF-8";
@@ -74,6 +76,12 @@
private HttpResponse rewritten;
+ @Inject @Named("http.cache.negativeCacheTtl")
+ private static long negativeCacheTtl = NEGATIVE_CACHE_TTL;
+
+ @Inject @Named("http.cache.defaultTtl")
+ private static long defaultTtl = DEFAULT_TTL;
+
// Holds character sets for fast conversion
private static ConcurrentHashMap<String,Charset> encodingToCharset
= new ConcurrentHashMap<String,Charset>();
@@ -92,6 +100,7 @@
*/
public HttpResponse(int httpStatusCode, byte[] responseBytes,
Map<String, List<String>> headers) {
+ System.out.println("Default TTL: " + defaultTtl);
this.httpStatusCode = httpStatusCode;
if (responseBytes == null) {
this.responseBytes = new byte[0];
@@ -288,7 +297,7 @@
*/
public long getCacheExpiration() {
if (httpStatusCode != SC_OK) {
- return getDate() + NEGATIVE_CACHE_TTL;
+ return getDate() + negativeCacheTtl;
}
if (isStrictNoCache()) {
return -1;
@@ -301,7 +310,7 @@
if (expiration != -1) {
return expiration;
}
- return getDate() + DEFAULT_TTL;
+ return getDate() + defaultTtl;
}
/**