Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion expression-src/main/src/interpreter/EnvironmentCache.cls
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ public with sharing class EnvironmentCache {
isStandardFunctionCacheDisabled = true;
}

public static void enableCache() {
isStandardFunctionCacheDisabled = false;
}

public static void cacheStandardFunctionCall(
Environment env,
Expr.FunctionCall function,
Object result
) {
cacheFunctionCall(isStandardFunctionCacheDisabled, env, function, result);
cacheFunctionCall(!isStandardFunctionCacheDisabled, env, function, result);
}

public static void cacheCustomMetadataFunctionCall(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@IsTest
private class EvaluatorCustomContextCacheTest {

@IsTest
static void standardFunctionCacheDisabled_doesNotReuseFirstCustomContext() {
Configuration config1 = new Configuration();
config1.cacheStandardFunctionResults = false;
config1.customContext = new Map<String, Object>{
'value' => 'first'
};

Configuration config2 = new Configuration();
config2.cacheStandardFunctionResults = false;
config2.customContext = new Map<String, Object>{
'value' => 'second'
};

Test.startTest();
Object firstResult = Evaluator.run('UPPER(@value)', config1);
Object secondResult = Evaluator.run('UPPER(@value)', config2);
Test.stopTest();

System.assertEquals(
'FIRST',
firstResult,
'First evaluation must use the first customContext, not cached result from first run.'
);
System.assertEquals(
'SECOND',
secondResult,
'Second evaluation must use the second customContext, not cached result from first run.'
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>65.0</apiVersion>
<status>Active</status>
</ApexClass>
4 changes: 3 additions & 1 deletion expression-src/main/src/resolver/EvaluatorResolver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public with sharing abstract class EvaluatorResolver {
eventNotifier.notify(new OnEvaluationStartEvent(config));

// Disable cache if disabled in the congif
if (!config.cacheStandardFunctionResults) {
if (config.cacheStandardFunctionResults) {
EnvironmentCache.enableCache();
} else {
EnvironmentCache.disableCache();
}

Expand Down
Loading