Hi, the caching has been very naughty :D
I have identified potential critical bugs, in the caching itself and also in the config. The issue in general is when calling multiple times Evaluator.run in the same transaction, the cache "kicks in". First issue was Query + Context variables.
It looks like the cache is ignoring context variables having different values.
Configuration config = new Configuration();
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test'
};
config.cacheStandardFunctionResults=true;
Object result = Evaluator.run('QUERY(Account(where: Name = @name))', config);
System.debug(result);
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test2'
};
config.cacheStandardFunctionResults=true;
Object result2 = Evaluator.run('QUERY(Account(where: Name = @name))', config);
System.debug(result2);
This will only run the query once ->
14:00:05.486 (823100979)|SOQL_EXECUTE_BEGIN|[22]|Aggregations:0|SELECT Id FROM Account WHERE Name = 'test'
14:00:05.486 (833403824)|SOQL_EXECUTE_END|[22]|Rows:0
14:00:05.486 (833577908)|SYSTEM_MODE_EXIT|true
14:00:05.486 (835646857)|SYSTEM_MODE_EXIT|false
14:00:05.486 (835694349)|USER_DEBUG|[10]|DEBUG|()
14:00:05.486 (835739322)|SYSTEM_MODE_ENTER|false
14:00:05.486 (835759572)|SYSTEM_MODE_EXIT|false
14:00:05.486 (835809407)|SYSTEM_MODE_ENTER|false
14:00:05.486 (845446611)|SYSTEM_MODE_EXIT|false
14:00:05.486 (845517635)|USER_DEBUG|[21]|DEBUG|()
14:00:05.845 (845605667)|CUMULATIVE_LIMIT_USAGE
14:00:05.845 (845605667)|LIMIT_USAGE_FOR_NS|(default)
Second issue - the standard functions + context variables:
Configuration config = new Configuration();
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test'
};
config.cacheStandardFunctionResults=false;
Object result = Evaluator.run('IF(@name="test",1,0)', config);
System.debug(result);
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test2'
};
Object result2 = Evaluator.run('IF(@name="test",1,0)', config);
System.debug(result2);
First result should be 1, second result should be 0. But
14:05:12.404 (462923082)|SYSTEM_MODE_EXIT|false
14:05:12.404 (462965464)|USER_DEBUG|[10]|DEBUG|1
14:05:12.404 (462994748)|SYSTEM_MODE_ENTER|false
14:05:12.404 (463021205)|SYSTEM_MODE_EXIT|false
14:05:12.404 (463067958)|SYSTEM_MODE_ENTER|false
14:05:12.404 (469742012)|SYSTEM_MODE_EXIT|false
14:05:12.404 (469782153)|USER_DEBUG|[20]|DEBUG|1
14:05:12.469 (469861669)|CUMULATIVE_LIMIT_USAGE
It always returns 1. UNLESS you actually enable the cache here. So
Configuration config = new Configuration();
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test'
};
config.cacheStandardFunctionResults=true;
Object result = Evaluator.run('IF(@name="test",1,0)', config);
System.debug(result);
config.respectSharing(false);
config.customContext = new Map<String, Object>{
'name' => 'test2'
};
Object result2 = Evaluator.run('IF(@name="test",1,0)', config);
System.debug(result2);
Has the correct result 1 and 0.
The strange behaviour I believe I am fixing in #238
But nevertheless I need to basically disable the cache on all occasions I am using custom context, because the caching ignores changing values of the context variables.
Hi, the caching has been very naughty :D
I have identified potential critical bugs, in the caching itself and also in the config. The issue in general is when calling multiple times Evaluator.run in the same transaction, the cache "kicks in". First issue was Query + Context variables.
It looks like the cache is ignoring context variables having different values.
This will only run the query once ->
Second issue - the standard functions + context variables:
First result should be 1, second result should be 0. But
It always returns 1. UNLESS you actually enable the cache here. So
Has the correct result 1 and 0.
The strange behaviour I believe I am fixing in #238
But nevertheless I need to basically disable the cache on all occasions I am using custom context, because the caching ignores changing values of the context variables.