LongCacheConfig.java
2.84 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.ui.clientlibs.impl;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LongCacheConfig {
private static final Logger log = LoggerFactory.getLogger(LongCacheConfig.class);
public static final String AUTO_SHARED_CACHE_KEY = "auto";
public static final String NONE_SHARED_CACHE_KEY = "none";
private final Entry[] longCacheEntries;
private final String longCacheAutoValue;
private String keyFormat = "lc-%s-lc";
public LongCacheConfig() {
this.longCacheAutoValue = String.valueOf(System.currentTimeMillis());
this.longCacheEntries = new Entry[0];
}
public LongCacheConfig(String[] patterns, String auto, String format) {
String string = this.longCacheAutoValue = auto == null ? String.valueOf(System.currentTimeMillis()) : auto;
if (format != null && format.length() > 0) {
this.keyFormat = format;
}
LinkedList<Entry> entries = new LinkedList<Entry>();
if (patterns != null) {
for (String p : patterns) {
int idx = p.indexOf(59);
String key = "auto";
if (idx > 0) {
key = p.substring(idx + 1).trim();
p = p.substring(0, idx);
}
try {
entries.add(new Entry(Pattern.compile(p), this.formatCacheKey(key)));
continue;
}
catch (PatternSyntaxException e) {
log.error("Error in long cache regexp: " + p, (Throwable)e);
}
}
}
this.longCacheEntries = entries.toArray(new Entry[entries.size()]);
}
public String formatCacheKey(String rawKey) {
if (rawKey == null || "none".equals(rawKey)) {
return null;
}
if ("auto".equals(rawKey)) {
rawKey = this.longCacheAutoValue;
}
return String.format(this.keyFormat, rawKey);
}
public String getCacheKey(String path) {
String key = null;
for (Entry entry : this.longCacheEntries) {
key = entry.getKeyIfMatches(path, key);
}
return key;
}
private static final class Entry {
private final Pattern pattern;
private final String key;
private Entry(Pattern pattern, String key) {
this.pattern = pattern;
this.key = key;
}
private String getKeyIfMatches(String path, String defaultValue) {
return this.pattern.matcher(path).matches() ? this.key : defaultValue;
}
}
}