Skip to content

Commit

Permalink
[symfony#6947] some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Nov 5, 2016
1 parent 152aecc commit f865f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions components/cache/cache_invalidation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ change in the state of your model. The most basic kind of invalidation is direct
items deletion. But when the state of a primary resource has spread accross
several cached items, keeping them in sync can be difficult.

The Symfony Cache component provides two mechanisms to help solve this problem:
The Symfony Cache component provides two mechanisms to help solving this problem:

* Tags based invalidation for managing data dependencies;
* Expiration based invalidation for time related dependencies.
* :ref:`Tags based invalidation <cache-component-tags>` for managing data dependencies;
* :ref:`Expiration based invalidation <cache-component-expiration>` for time related dependencies.

.. versionadded:: 3.2
Tags based invalidation was introduced in Symfony 3.2.
.. _cache-component-tags:

Using Cache Tags
----------------

.. versionadded:: 3.2
Tags based invalidation was introduced in Symfony 3.2.

To benefit from tags based invalidation, you need to attach the proper tags to
each cached items. Each tag is a plain string identifier that you can use at any
time to trigger the removal of all items that had this tag attached to them.
each cached item. Each tag is a plain string identifier that you can use at any
time to trigger the removal of all items associated with this tag.

To attach tags to cached items, you need to use the
:method:`Symfony\\Component\\Cache\\CacheItem::tag` method that is implemented by
Expand All @@ -36,14 +38,14 @@ cache items, as returned by cache adapters::
$item->tag(array('tag_2', 'tag_3'));
$cache->save($item);

If ``$cache`` implements :class:`Symfony\\Component\\Cache\\TagAwareAdapterInterface`,
If ``$cache`` implements :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapterInterface`,
you can invalidate the cached items by calling
:method:`Symfony\\Component\\Cache\\TagAwareAdapterInterface::invalidateTags`::
:method:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapterInterface::invalidateTags`::

// invalidate all items related to `tag_1` or `tag_3`
$cache->invalidateTags(array('tag_1', 'tag_3'));

// if you know the cache key, you can of course delete directly
// if you know the cache key, you can also delete the item directly
$cache->deleteItem('cache_key');

Using tags invalidation is very useful when tracking cache keys becomes difficult.
Expand Down Expand Up @@ -78,6 +80,8 @@ your fronts and have very fast invalidation checks::
new RedisAdapter('redis://localhost')
);

.. _cache-component-expiration:

Using Cache Expiration
----------------------

Expand Down
6 changes: 3 additions & 3 deletions components/cache/cache_pools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ See the method's docblock for more options.
PDO & Doctrine DBAL Cache Adapter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 3.2
The PDO & Doctrine DBAL adapter was introduced in Symfony 3.2.

This adapter stores the cached items a SQL database accessed through a PDO or a
Doctrine DBAL connection::

Expand All @@ -130,9 +133,6 @@ Doctrine DBAL connection::
$options = array()
);

.. versionadded:: 3.2
The PDO & Doctrine DBAL adapter was introduced in Symfony 3.2.

Chain Cache Adapter
~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit f865f93

Please sign in to comment.