8000 initial documentation for cache pruning · symfony/symfony-docs@397ef14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 397ef14

Browse files
committed
initial documentation for cache pruning
1 parent ab53d29 commit 397ef14

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

components/cache/adapters/chain_adapter.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ slowest storage engines, :class:`Symfony\\Component\\Cache\\Adapter\\ApcuAdapter
4141
new ApcuAdapter(),
4242
new FilesystemAdapter(),
4343
));
44+
45+
.. note::
46+
47+
This adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`, allowing
48+
for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
49+
calling it's ``prune()`` method.

components/cache/adapters/filesystem_adapter.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ directory path, as its first, second, and third parameters::
3636
the in-memory adapters (such as :ref:`APCu <apcu-adapter>`, :ref:`Memcached <memcached-adapter>`,
3737
and :ref:`Redis <redis-adapter>`) or the database adapters (such as
3838
:ref:`Doctrine <doctrine-adapter>` and :ref:`PDO & Doctrine <pdo-doctrine-adapter>`) are recommended.
39+
40+
.. note::
41+
42+
This adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`, allowing
43+
for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
44+
calling it's ``prune()`` method.

components/cache/adapters/pdo_doctrine_dbal_adapter.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ third, and forth parameters::
4141
When passed a `Data Source Name (DSN)`_ string (instead of a database connection
4242
class instance), the connection will be lazy-loaded when needed.
4343

44+
.. note::
45+
46+
This adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`, allowing
47+
for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
48+
calling it's ``prune()`` method.
49+
4450
.. _`PDO`: http://php.net/manual/en/class.pdo.php
4551
.. _`Doctrine DBAL Connection`: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php
4652
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name

components/cache/cache_pools.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,32 @@ when all items are successfully deleted)::
121121

122122
// ...
123123
$cacheIsEmpty = $cache->clear();
124+
125+
.. _component-cache-cache-pool-prune:
126+
127+
Pruning Cache Items
128+
-------------------
129+
130+
.. versionadded:: 3.4
131+
132+
Pruning functionality was introduced in Symfony 3.4.
133+
134+
Some cache pools do not include an automated mechanism for pruning expired cache
135+
items. For example, :class:`Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter`
136+
does not remove expired items until one is explicitly requested and determined to
137+
be expired, for example, via a call to :method:`Psr\\Cache\\CacheItemPoolInterface::getItem`.
138+
This may result in many stale cache entries persisting well past their expiration,
139+
causing a build up that can result in a sizable consumption of wasted disk or memory
140+
space.
141+
142+
This concern has been resolved through the introduction of
143+
:class:`Symfony\\Component\\Cache\\PruneableInterface`, an interface defining a
144+
singular ``prune()`` method. Relevant cache adapters, those that allow expired cache
145+
entries to proliferate, now implement ``PruneableInterface``, allowing for these
146+
excess cache entries to be manually removed::
147+
148+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
149+
150+
$cache = new FilesystemAdapter('app.cache');
151+
// ... do some set and get operations
152+
$cache->prune();

0 commit comments

Comments
 (0)
0