1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.esigate.extension.parallelesi;
16
17 import java.util.Date;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 final class InlineCache {
22 private static final Map<String, InlineCache> CACHE = new HashMap<>();
23
24 private final Date outdate;
25 private final boolean fetchable;
26 private final String originalUrl;
27 private final String fragment;
28
29 public static void storeFragment(String uri, Date outdate, boolean fetchable, String originalUrl, String fragment) {
30 InlineCache ic = new InlineCache(outdate, fetchable, originalUrl, fragment);
31 CACHE.put(uri, ic);
32 }
33
34 public static InlineCache getFragment(String uri) {
35 return CACHE.get(uri);
36 }
37
38 private InlineCache(Date outdate, boolean fetchable, String originalUrl, String fragment) {
39 this.outdate = outdate;
40 this.fetchable = fetchable;
41 this.originalUrl = originalUrl;
42 this.fragment = fragment;
43 }
44
45 public boolean isExpired() {
46 return (outdate != null) && (outdate.getTime() < System.currentTimeMillis());
47 }
48
49 public Date getOutdate() {
50 return outdate;
51 }
52
53 public boolean isFetchable() {
54 return fetchable;
55 }
56
57 public String getOriginalUrl() {
58 return originalUrl;
59 }
60
61 public String getFragment() {
62 return fragment;
63 }
64
65 }