CatalogCachingPolicy.java
2.94 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
90
91
92
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.sleng.CacheAction
* com.scene7.is.sleng.CacheEnum
*/
package com.scene7.is.ps.provider.util;
import com.scene7.is.ps.provider.util.CachingPolicy;
import com.scene7.is.sleng.CacheAction;
import com.scene7.is.sleng.CacheEnum;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CatalogCachingPolicy
implements CachingPolicy,
Serializable {
private static final Logger LOGGER = Logger.getLogger(CatalogCachingPolicy.class.getName());
private final CacheEnum cacheUse;
private final long catalogTimeStamp;
public CatalogCachingPolicy(CacheEnum useCache, long timeStamp) {
this.cacheUse = useCache;
this.catalogTimeStamp = CatalogCachingPolicy.truncToSec(timeStamp);
}
@Override
public boolean cacheEnabled() {
return this.cacheUse != CacheEnum.OFF;
}
@Override
public long getValidationTime() {
return this.catalogTimeStamp;
}
@Override
public CacheAction getCacheHitAction(long cacheTimeStamp) {
switch (this.cacheUse) {
case VALIDATE: {
return CacheAction.VALIDATE;
}
case UPDATE: {
return CacheAction.UPDATE;
}
case DELETE: {
return CacheAction.DELETE;
}
case ON: {
if (this.catalogTimeStamp != CatalogCachingPolicy.truncToSec(cacheTimeStamp)) {
LOGGER.log(Level.FINE, "Need to validate cache. Catalog time stamp is " + this.catalogTimeStamp + " and cache time stamp truncated to second is " + CatalogCachingPolicy.truncToSec(cacheTimeStamp));
return CacheAction.VALIDATE;
}
LOGGER.log(Level.FINE, "No need to validate cache. Catalog time stamp is " + this.catalogTimeStamp + " and cache time stamp truncated to second is " + CatalogCachingPolicy.truncToSec(cacheTimeStamp));
return CacheAction.REUSE;
}
case OFF: {
throw new IllegalStateException("Attempt to access cache entry when caching is turned \"off\"");
}
}
throw new AssertionError((Object)("Unsupported cacheUse value: " + (Object)this.cacheUse));
}
@Override
public CacheAction getCacheMissAction() {
switch (this.cacheUse) {
case DELETE:
case OFF: {
return CacheAction.IGNORE;
}
case VALIDATE:
case UPDATE:
case ON: {
return CacheAction.CREATE;
}
}
throw new AssertionError((Object)("Unsupported cacheUse value: " + (Object)this.cacheUse));
}
@Override
public CacheEnum getCacheSetting() {
return this.cacheUse;
}
private static long truncToSec(long value) {
return value / 1000 * 1000;
}
}