|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.web.filter; |
|
6 |
| |
|
7 |
| import com.opensymphony.oscache.base.CacheEntry; |
|
8 |
| import com.opensymphony.oscache.base.EntryRefreshPolicy; |
|
9 |
| import com.opensymphony.oscache.base.NeedsRefreshException; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| public class ExpiresRefreshPolicy implements EntryRefreshPolicy { |
|
19 |
| |
|
20 |
| |
|
21 |
| private long refreshPeriod; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
0
| public ExpiresRefreshPolicy(int refreshPeriod) {
|
|
29 |
0
| this.refreshPeriod = refreshPeriod * 1000L;
|
|
30 |
| } |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
0
| public boolean needsRefresh(CacheEntry entry) {
|
|
45 |
| |
|
46 |
0
| long currentTimeMillis = System.currentTimeMillis();
|
|
47 |
| |
|
48 |
0
| if ((refreshPeriod >= 0) && (currentTimeMillis >= (entry.getLastUpdate() + refreshPeriod))) {
|
|
49 |
0
| return true;
|
|
50 |
0
| } else if (entry.getContent() instanceof ResponseContent) {
|
|
51 |
0
| ResponseContent responseContent = (ResponseContent) entry.getContent();
|
|
52 |
0
| return currentTimeMillis >= responseContent.getExpires();
|
|
53 |
| } else { |
|
54 |
0
| return false;
|
|
55 |
| } |
|
56 |
| |
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
0
| public long getRefreshPeriod() {
|
|
64 |
0
| return refreshPeriod / 1000;
|
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
0
| public void setRefreshPeriod(long refreshPeriod) {
|
|
72 |
0
| this.refreshPeriod = refreshPeriod * 1000L;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| } |