Skip to content

Update caching.rst #7064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2016
Merged
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
22 changes: 9 additions & 13 deletions components/expression_language/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,21 @@ expression saved in the ``ParsedExpression``) and evaluate them on the fly.

To save time, the ``ExpressionLanguage`` caches the ``ParsedExpression`` so
it can skip the tokenize and parse steps with duplicate expressions.
The caching is done by a
:class:`Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface`
instance (by default, it uses an
:class:`Symfony\\Component\\ExpressionLanguage\\ParserCache\\ArrayParserCache`).
You can customize this by creating a custom ``ParserCache`` and injecting this
The caching is done by a `CacheItemPoolInterface`_ instance (by default, it uses an
:class:`Symfony\\Component\\Cache\\Adapter\\ArrayAdapter`).
You can customize this by creating a custom ``Cache`` and injecting this
in the object using the constructor::

use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Acme\ExpressionLanguage\ParserCache\MyDatabaseParserCache;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$cache = new MyDatabaseParserCache(...);
$cache = new RedisAdapter(...);
$language = new ExpressionLanguage($cache);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe enhance this a bit, to show we're really doing PSR-6 here?

E.g. by showing something like:

use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Cache\RedisAdapter;

$cache = new RedisAdapter(...);
$language = new ExpressionLanguage($cache);

Then, we can add a small "seealso" box pointing to the cache component:

.. seealso::

    See the :doc:`/components/cache` documentation for more information about
    available cache adapters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your help, I agree, I'll do it as soon as possible :)


.. note::
.. seealso::

The `DoctrineBridge`_ provides a Parser Cache implementation using the
`doctrine cache library`_, which gives you caching for all sorts of cache
strategies, like Apc, Filesystem and Memcached.
See the :doc:`/components/cache` documentation for more information about
available cache adapters.

Using Parsed and Serialized Expressions
---------------------------------------
Expand All @@ -70,5 +67,4 @@ Both ``evaluate()`` and ``compile()`` can handle ``ParsedExpression`` and

var_dump($language->evaluate($expression)); // prints 5

.. _DoctrineBridge: https://github.com/symfony/doctrine-bridge
.. _`doctrine cache library`: http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/caching.html
.. _`CacheItemPoolInterface`: https://github.com/php-fig/cache/blob/master/src/CacheItemPoolInterface.php