From 18f4e49c938471866ed4c99cd6bfa5295d08bbc3 Mon Sep 17 00:00:00 2001 From: Vit Bares Date: Mon, 18 May 2026 14:32:31 +0200 Subject: [PATCH] fix: caching: resetting global static variable for each run, fixed actual setting of caching true/false --- .../main/src/interpreter/EnvironmentCache.cls | 6 +++- .../tests/EvaluatorCustomContextCacheTest.cls | 35 +++++++++++++++++++ ...aluatorCustomContextCacheTest.cls-meta.xml | 5 +++ .../main/src/resolver/EvaluatorResolver.cls | 4 ++- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls create mode 100644 expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls-meta.xml diff --git a/expression-src/main/src/interpreter/EnvironmentCache.cls b/expression-src/main/src/interpreter/EnvironmentCache.cls index ab482af1..f69c57b7 100644 --- a/expression-src/main/src/interpreter/EnvironmentCache.cls +++ b/expression-src/main/src/interpreter/EnvironmentCache.cls @@ -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( diff --git a/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls b/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls new file mode 100644 index 00000000..c001b032 --- /dev/null +++ b/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls @@ -0,0 +1,35 @@ +@IsTest +private class EvaluatorCustomContextCacheTest { + + @IsTest + static void standardFunctionCacheDisabled_doesNotReuseFirstCustomContext() { + Configuration config1 = new Configuration(); + config1.cacheStandardFunctionResults = false; + config1.customContext = new Map{ + 'value' => 'first' + }; + + Configuration config2 = new Configuration(); + config2.cacheStandardFunctionResults = false; + config2.customContext = new Map{ + '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.' + ); + } + +} \ No newline at end of file diff --git a/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls-meta.xml b/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls-meta.xml new file mode 100644 index 00000000..82775b98 --- /dev/null +++ b/expression-src/main/src/interpreter/tests/EvaluatorCustomContextCacheTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 65.0 + Active + diff --git a/expression-src/main/src/resolver/EvaluatorResolver.cls b/expression-src/main/src/resolver/EvaluatorResolver.cls index 889eb89a..94093923 100644 --- a/expression-src/main/src/resolver/EvaluatorResolver.cls +++ b/expression-src/main/src/resolver/EvaluatorResolver.cls @@ -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(); }