Skip to content

Commit 0552c47

Browse files
authored
fix: caching: resetting global static variable for each run, fixed actual setting of caching true/false (#238)
1 parent acbd137 commit 0552c47

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

expression-src/main/src/interpreter/EnvironmentCache.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ public with sharing class EnvironmentCache {
1010
isStandardFunctionCacheDisabled = true;
1111
}
1212

13+
public static void enableCache() {
14+
isStandardFunctionCacheDisabled = false;
15+
}
16+
1317
public static void cacheStandardFunctionCall(
1418
Environment env,
1519
Expr.FunctionCall function,
1620
Object result
1721
) {
18-
cacheFunctionCall(isStandardFunctionCacheDisabled, env, function, result);
22+
cacheFunctionCall(!isStandardFunctionCacheDisabled, env, function, result);
1923
}
2024

2125
public static void cacheCustomMetadataFunctionCall(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@IsTest
2+
private class EvaluatorCustomContextCacheTest {
3+
4+
@IsTest
5+
static void standardFunctionCacheDisabled_doesNotReuseFirstCustomContext() {
6+
Configuration config1 = new Configuration();
7+
config1.cacheStandardFunctionResults = false;
8+
config1.customContext = new Map<String, Object>{
9+
'value' => 'first'
10+
};
11+
12+
Configuration config2 = new Configuration();
13+
config2.cacheStandardFunctionResults = false;
14+
config2.customContext = new Map<String, Object>{
15+
'value' => 'second'
16+
};
17+
18+
Test.startTest();
19+
Object firstResult = Evaluator.run('UPPER(@value)', config1);
20+
Object secondResult = Evaluator.run('UPPER(@value)', config2);
21+
Test.stopTest();
22+
23+
System.assertEquals(
24+
'FIRST',
25+
firstResult,
26+
'First evaluation must use the first customContext, not cached result from first run.'
27+
);
28+
System.assertEquals(
29+
'SECOND',
30+
secondResult,
31+
'Second evaluation must use the second customContext, not cached result from first run.'
32+
);
33+
}
34+
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>65.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

expression-src/main/src/resolver/EvaluatorResolver.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public with sharing abstract class EvaluatorResolver {
8787
eventNotifier.notify(new OnEvaluationStartEvent(config));
8888

8989
// Disable cache if disabled in the congif
90-
if (!config.cacheStandardFunctionResults) {
90+
if (config.cacheStandardFunctionResults) {
91+
EnvironmentCache.enableCache();
92+
} else {
9193
EnvironmentCache.disableCache();
9294
}
9395

0 commit comments

Comments
 (0)