|
1 | 1 | .. index::
|
2 | 2 | single: Caching; ExpressionLanguage
|
3 | 3 |
|
4 |
| -Caching Expressions Using ParserCaches |
5 |
| -====================================== |
| 4 | +Caching Expressions Using Parser Caches |
| 5 | +======================================= |
6 | 6 |
|
7 | 7 | The ExpressionLanguage component already provides a
|
8 |
| -:method:`Symfony\\Component\\ExpresionLanguage\\ExpressionLanguage::compile` |
| 8 | +:method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::compile` |
9 | 9 | method to be able to cache the expressions in plain PHP. But internally, the
|
10 | 10 | component also caches the parsed expressions, so duplicated expressions can be
|
11 | 11 | compiled/evaluated quicker.
|
12 | 12 |
|
13 | 13 | The Workflow
|
14 | 14 | ------------
|
15 | 15 |
|
16 |
| -Both ``evaluate`` and ``compile`` needs to do some things before it can |
| 16 | +Both ``evaluate`` and ``compile`` need to do some things before each can |
17 | 17 | provide the return values. For ``evaluate``, this overhead is even bigger.
|
18 | 18 |
|
19 | 19 | Both methods need to tokenize and parse the expression. This is done by the
|
20 | 20 | :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::parse`
|
21 |
| -method. It'll return a :class:`Symfony\\Component\\ExpressionLanguage\\ParsedExpression`. |
| 21 | +method. It returns a :class:`Symfony\\Component\\ExpressionLanguage\\ParsedExpression`. |
22 | 22 | Now, the ``compile`` method just returns the string conversion of this object.
|
23 | 23 | The ``evaluate`` method needs to loop through the "nodes" (pieces of an
|
24 | 24 | expression saved in the ``ParsedExpression``) and evaluate them on the fly.
|
25 | 25 |
|
26 |
| -To save time, the ``ExpressionLanguage`` caches the ``ParsedExpression``, so |
| 26 | +To save time, the ``ExpressionLanguage`` caches the ``ParsedExpression`` so |
27 | 27 | it can skip the tokenize and parse steps with duplicate expressions.
|
28 | 28 | The caching is done by a
|
29 | 29 | :class:`Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface`
|
|
0 commit comments