1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.exoplatform.services.portletcache;
21
22 import org.exoplatform.commons.cache.future.Loader;
23 import org.exoplatform.services.log.Log;
24
25
26
27
28
29 class PortletRenderer implements Loader<WindowKey, MarkupFragment, PortletRenderContext>
30 {
31
32
33 private final Log log;
34
35 PortletRenderer(Log log)
36 {
37 this.log = log;
38 }
39
40 public MarkupFragment retrieve(PortletRenderContext context, WindowKey key) throws Exception
41 {
42 BufferedRenderResponse bufferedResp = new BufferedRenderResponse(context.resp);
43 context.chain.doFilter(context.req, bufferedResp);
44
45
46 long now = System.currentTimeMillis();
47
48
49 String expirationCache = bufferedResp.getExpirationCache();
50 long expirationCacheMillis = now;
51 if (expirationCache != null)
52 {
53 try
54 {
55 int expirationCacheSec = Integer.parseInt(expirationCache);
56 if (expirationCacheSec == -1)
57 {
58 expirationCacheMillis = Long.MAX_VALUE;
59 }
60 else if (expirationCacheSec > 0)
61 {
62 expirationCacheMillis += 1000 * expirationCacheSec;
63 }
64 }
65 catch (NumberFormatException e)
66 {
67 if (log.isWarnEnabled()) {
68 log.warn("Incorrect expiration cache value " + expirationCache);
69 }
70 }
71 }
72
73
74 return new MarkupFragment(expirationCacheMillis, bufferedResp.getBytes());
75 }
76 }