FvctxCachingPolicy.java
3.62 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.provider.CacheSpec
* com.scene7.is.provider.catalog.Catalog
* com.scene7.is.provider.catalog.ObjectRecord
* com.scene7.is.sleng.CacheAction
* com.scene7.is.sleng.CacheEnum
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider.fvctx;
import com.scene7.is.provider.CacheSpec;
import com.scene7.is.provider.catalog.Catalog;
import com.scene7.is.provider.catalog.ObjectRecord;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.Util;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.ps.provider.util.CachingPolicy;
import com.scene7.is.ps.provider.util.NoCacheCachingPolicy$;
import com.scene7.is.sleng.CacheAction;
import com.scene7.is.sleng.CacheEnum;
import org.jetbrains.annotations.NotNull;
public class FvctxCachingPolicy
implements CachingPolicy {
@NotNull
private final CacheEnum cacheUse;
private final long catalogTimeStamp;
public static CachingPolicy createFvctxCachingPolicy(boolean useCache, boolean useMainRecordValidation, @NotNull Request request) {
if (useCache) {
Catalog catalog = request.getRecord().getCatalog();
ModifierSet attributes = request.getGlobalAttributes();
boolean useCatalogValidation = catalog.getCatalogBasedValidation();
CacheEnum cacheUse = attributes.get(ModifierEnum.CACHE, CacheSpec.ON).getServer();
if (useMainRecordValidation && useCatalogValidation) {
return new FvctxCachingPolicy(cacheUse, Util.computeCatalogTimeStamp(request));
}
return new FvctxCachingPolicy(cacheUse, catalog.getCompileTimeStamp());
}
return NoCacheCachingPolicy$.MODULE$;
}
@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:
case UPDATE: {
return CacheAction.UPDATE;
}
case DELETE: {
return CacheAction.DELETE;
}
case ON: {
if (this.catalogTimeStamp != FvctxCachingPolicy.truncToSec(cacheTimeStamp)) {
return CacheAction.UPDATE;
}
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 FvctxCachingPolicy(@NotNull CacheEnum useCache, long timeStamp) {
this.cacheUse = useCache;
this.catalogTimeStamp = FvctxCachingPolicy.truncToSec(timeStamp);
}
private static long truncToSec(long value) {
return value / 1000 * 1000;
}
}