Skip to content

Commit cb839b8

Browse files
committed
nocache keyword deprecation
1 parent d3da670 commit cb839b8

File tree

11 files changed

+15
-72
lines changed

11 files changed

+15
-72
lines changed

docs/src/app/docs/declaring-functions/page.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ The Expression language will cache the result of a function call, so if a functi
9292
same
9393
arguments and is within the same context, the result will be cached and the function will not be re-evaluated.
9494

95-
This can be usedful when you have an evaluation that is expensive to compute, such as a `Query` call, and you want to
96-
reuse the result multiple times within the same expression.
97-
9895
```
9996
fun foo(n) => Query(Account(where: Name = n)[Name]);
10097
@@ -104,17 +101,6 @@ fun foo(n) => Query(Account(where: Name = n)[Name]);
104101
In this example, the `foo` function will only be evaluated once for the `ACME` account, and the result will be reused
105102
for the second call. This means that a single query will be consumed from the Salesforce limits.
106103

107-
### Disabling Caching
108-
109-
Function caching can be disabled by using the `nocache` keyword after the `fun` keyword. This will force the function to
110-
be re-evaluated every time it is called, even if the arguments are the same.
111-
112-
```
113-
fun nocache foo(n) => Query(Account(where: Name = n)[Name]);
114-
115-
[...foo("ACME"), ...foo("ACME")]
116-
```
117-
118104
## Considerations
119105

120106
- Names given to functions will superse any of the language's built-in functions. So if you declare a `sum` function,

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
// TODO: One issue with caching
3-
// is that some can be globally cached (like a raw query)
4-
// while others depend on the environment
5-
61
public abstract class Expr {
72
public abstract Object accept(Visitor v);
83

@@ -100,14 +95,12 @@ public abstract class Expr {
10095
public final Token name;
10196
public final List<Token> parameters;
10297
public final Expr body;
103-
public final Boolean skipCache;
10498
private final Map<Environment, Object> cachedValueForEnvironment = new Map<Environment, Object>();
10599

106-
public FunctionDeclaration(Token name, List<Token> parameters, Expr body, Boolean skipCache) {
100+
public FunctionDeclaration(Token name, List<Token> parameters, Expr body) {
107101
this.name = name;
108102
this.parameters = parameters;
109103
this.body = body;
110-
this.skipCache = skipCache;
111104
}
112105

113106
public String functionName {
@@ -131,23 +124,14 @@ public abstract class Expr {
131124
}
132125

133126
public void cache(Environment env, Object cachedValue) {
134-
if (skipCache) {
135-
return;
136-
}
137127
cachedValueForEnvironment.put(env, cachedValue);
138128
}
139129

140130
public Boolean isCachedForEnvironment(Environment env) {
141-
if (skipCache) {
142-
return false;
143-
}
144131
return cachedValueForEnvironment.containsKey(env);
145132
}
146133

147134
public Object getCachedValueForEnvironment(Environment env) {
148-
if (skipCache) {
149-
return null;
150-
}
151135
return cachedValueForEnvironment.get(env);
152136
}
153137
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ public virtual with sharing class Interpreter implements Visitor {
477477
return functionDeclaration;
478478
}
479479

480-
// Declarations should not be called
481-
// by the EvaluatorResolver.
480+
// Declarations should not be called by the EvaluatorResolver.
482481
// Reaching this point means a declaration exists within another expression and not at the top level,
483482
// which is not valid.
484483
throw new Exceptions.RuntimeException(

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ public with sharing class Parser {
4545

4646
private Expr functionDeclarationCheck() {
4747
if (match(TokenType.FUNCTION_KEYWORD)) {
48-
Boolean skipCache = false;
49-
50-
// The fun keyword might be followed (optionally) by the nocache keyword
51-
if (match(TokenType.NOCACHE_KEYWORD)) {
52-
skipCache = true;
53-
}
54-
5548
Token name = consume(TokenType.IDENTIFIER, 'Expect function name.');
5649
consume(TokenType.LEFT_PAREN, 'Expect \'(\' after function name.');
5750
List<Token> parameters = new List<Token>();
@@ -68,7 +61,7 @@ public with sharing class Parser {
6861
consume(TokenType.FAT_ARROW, 'Expect \'=>\' before function body.');
6962
Expr body = expression();
7063
consume(TokenType.SEMICOLON, 'Expect \';\' after function body.');
71-
return new Expr.FunctionDeclaration(name, parameters, body, skipCache);
64+
return new Expr.FunctionDeclaration(name, parameters, body);
7265
}
7366
return orCheck();
7467
}
@@ -334,7 +327,7 @@ public with sharing class Parser {
334327
if (match(TokenType.FAT_ARROW)) {
335328
Expr body = expression();
336329
// Pass null as the name since it's anonymous
337-
return new Expr.FunctionDeclaration(null, parameters, body, true);
330+
return new Expr.FunctionDeclaration(null, parameters, body);
338331
}
339332
}
340333

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
public with sharing class PipeResolver implements Visitor {
55
public Expr resolve(Expr expr) {
6-
return (Expr) expr.accept(this);
6+
return (Expr)expr.accept(this);
77
}
88

99
public Object visit(Expr.Logical logical) {
@@ -27,7 +27,7 @@ public with sharing class PipeResolver implements Visitor {
2727
}
2828

2929
// Add the left side as the first argument to the function call
30-
Expr.FunctionCall function = (Expr.FunctionCall) binary.right;
30+
Expr.FunctionCall function = (Expr.FunctionCall)binary.right;
3131
if (function.arguments.isEmpty()) {
3232
function.arguments.add(binary.left);
3333
} else {
@@ -119,16 +119,16 @@ public with sharing class PipeResolver implements Visitor {
119119
List<Object> newElements = new List<Object>();
120120
for (Object element : mapLiteral.elements) {
121121
if (element instanceof Expr.Spread) {
122-
newElements.add(resolve((Expr) element));
122+
newElements.add(resolve((Expr)element));
123123
continue;
124124
}
125125

126126
if (element instanceof Expr.AddIfExpr) {
127-
newElements.add(resolve((Expr) element));
127+
newElements.add(resolve((Expr)element));
128128
continue;
129129
}
130130

131-
Expr.KeyValue keyValue = (Expr.KeyValue) element;
131+
Expr.KeyValue keyValue = (Expr.KeyValue)element;
132132
Expr.KeyValue newKeyValue = new Expr.KeyValue(
133133
resolve(keyValue.key),
134134
resolve(keyValue.value)
@@ -186,8 +186,7 @@ public with sharing class PipeResolver implements Visitor {
186186
return new Expr.FunctionDeclaration(
187187
functionDeclaration.name,
188188
functionDeclaration.parameters,
189-
resolvedBody,
190-
functionDeclaration.skipCache
189+
resolvedBody
191190
);
192191
}
193192

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>60.0</apiVersion>
3+
<apiVersion>65.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ public with sharing class Scanner {
1818
keywords.put('asc', TokenType.ASC_KEYWORD);
1919
keywords.put('desc', TokenType.DESC_KEYWORD);
2020
keywords.put('fun', TokenType.FUNCTION_KEYWORD);
21-
keywords.put('nocache', TokenType.NOCACHE_KEYWORD);
2221
keywords.put('addif', TokenType.ADD_IF_KEYWORD);
2322
}
2423

2524
public Scanner(String source) {
2625
this.source = normalizeCurvedQuotes(source);
2726
}
2827

29-
private String normalizeCurvedQuotes(String input) {
28+
private static String normalizeCurvedQuotes(String input) {
3029
if (input == null) return null;
3130
return input.replace('', '"').replace('', '"');
3231
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>60.0</apiVersion>
3+
<apiVersion>65.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>60.0</apiVersion>
3+
<apiVersion>65.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public enum TokenType {
3434
ASC_KEYWORD, DESC_KEYWORD, ADD_IF_KEYWORD,
3535

3636
// ----------------- Functions ----------------------
37-
FUNCTION_KEYWORD, FAT_ARROW, SEMICOLON, NOCACHE_KEYWORD,
37+
FUNCTION_KEYWORD, FAT_ARROW, SEMICOLON,
3838

3939
// ----------------- EOF ----------------------
4040
EOF

0 commit comments

Comments
 (0)