11
11
import java .util .Arrays ;
12
12
import java .util .Date ;
13
13
import java .util .List ;
14
+ import java .util .concurrent .atomic .AtomicBoolean ;
14
15
15
16
import javax .servlet .ServletException ;
16
17
import javax .servlet .http .HttpServletRequest ;
@@ -38,6 +39,11 @@ public class CacheManifestHttpRequestHandler extends WebContentGenerator impleme
38
39
39
40
private static final MediaType CONTENT_TYPE = new MediaType ("text" ,"cache-manifest" , Charset .forName ("UTF-8" ));
40
41
42
+ //TODO - This is a crude way of handling Chrome's duplicate request -
43
+ //could be improved later with a configurable refresh period, but since this is
44
+ //intended to be a development-time setting, this might be good enough
45
+ //private AtomicBoolean expired = new AtomicBoolean(true);
46
+
41
47
private boolean alwaysRegenerate = false ;
42
48
43
49
private List <Resource > cachedResources ;
@@ -46,6 +52,9 @@ public class CacheManifestHttpRequestHandler extends WebContentGenerator impleme
46
52
47
53
public CacheManifestHttpRequestHandler () {
48
54
super (METHOD_GET , METHOD_HEAD );
55
+ //if (alwaysRegenerate) {
56
+ // setCacheSeconds(5);
57
+ //}
49
58
}
50
59
51
60
public void handleRequest (HttpServletRequest request ,
@@ -73,7 +82,11 @@ protected CacheManifest getCacheManifest(HttpServletRequest request) throws IOEx
73
82
//TODO - Implement handling for NETWORK and FALLBACK sections of manifest
74
83
String key = (String ) request .getAttribute (HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
75
84
CacheManifest manifest = store .get (key );
76
- if (manifest != null && manifest .getHash ().equals (getHash ())) {
85
+ if (manifest != null && alwaysRegenerate && (manifest .getTimestamp () + 5000L ) >= new Date ().getTime ()) {
86
+ return manifest ;
87
+ }
88
+ String hash = getHash ();
89
+ if (manifest != null && manifest .getHash ().equals (hash )) {
77
90
return manifest ;
78
91
}
79
92
@@ -88,8 +101,7 @@ protected CacheManifest getCacheManifest(HttpServletRequest request) throws IOEx
88
101
}
89
102
writer .println (NETWORK_SECTION );
90
103
writer .println ("*" );
91
- String hash = getHash ();
92
- writer .println ("#SHA-1: " +getHash ());
104
+ writer .println ("#SHA-1: " +hash );
93
105
writer .flush ();
94
106
writer .close ();
95
107
@@ -148,4 +160,8 @@ public static char[] encode(byte[] bytes) {
148
160
return result ;
149
161
}
150
162
}
163
+
164
+ public void setAlwaysRegenerate (boolean alwaysRegenerate ) {
165
+ this .alwaysRegenerate = alwaysRegenerate ;
166
+ }
151
167
}
0 commit comments