/
Service.java
executable file
·35 lines (27 loc) · 1.13 KB
/
Service.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package controllers.greenscript;
import play.modules.greenscript.GreenScriptPlugin;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Scope.Flash;
import java.util.Map;
public class Service extends Controller {
public static void getInMemoryCache(String key) {
String content = GreenScriptPlugin.getInstance().getInMemoryFileContent(key, params.get(GreenScriptPlugin.RESOURCES_PARAM));
notFoundIfNull(content);
final long l = System.currentTimeMillis();
final String etag = "\"" + l + "-" + key.hashCode() + "\"";
response.cacheFor(etag, "100d", l);
Flash.current().keep();
if (key.endsWith(".js")) {
response.setContentTypeIfNotSet("text/javascript");
} else if (key.endsWith(".css")) {
response.setContentTypeIfNotSet("text/css");
}
Map<String, Http.Header> headers = request.headers;
if (headers.containsKey("if-none-match") && headers.containsKey("if-modified-since")) {
response.status = Http.StatusCode.NOT_MODIFIED;
return;
}
renderText(content);
}
}