Skip to content

Commit 015703b

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Mentioned the TargetPathTrait utility Added a mention to the createTable() method of the session handler Remove out-of-context rewrite rule tip document cache pruning functionality Mention cachetool utility to clear OPcache cache from CLI Documented the use of PHP streams as the process input
2 parents c5882ec + e91c5f9 commit 015703b

14 files changed

+288
-43
lines changed

components/cache/adapters/apcu_adapter.rst

+11-15
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
APCu Cache Adapter
88
==================
99

10-
This adapter is a high-performance, shared memory cache. It can increase the
11-
application performance very significantly because the cache contents are
12-
stored in the shared memory of your server, a component that is much faster than
13-
others, such as the filesystem.
10+
This adapter is a high-performance, shared memory cache. It can *significantly*
11+
increase an application's performance, as its cache contents are stored in shared
12+
memory, a component appreciably faster than many others, such as the filesystem.
1413

1514
.. caution::
1615

1716
**Requirement:** The `APCu extension`_ must be installed and active to use
1817
this adapter.
1918

20-
This adapter can be provided an optional namespace string as its first parameter, a
21-
default cache lifetime as its second parameter, and a version string as its third
22-
parameter::
19+
The ApcuAdapter can optionally be provided a namespace, default cache lifetime,
20+
and cache items version string as constructor arguments::
2321

2422
use Symfony\Component\Cache\Adapter\ApcuAdapter;
2523

@@ -40,15 +38,13 @@ parameter::
4038

4139
.. caution::
4240

43-
It is *not* recommended to use this adapter when performing a large number of
44-
write and delete operations, as these operations result in fragmentation of the
45-
APCu memory, resulting in *significantly* degraded performance.
41+
Use of this adapter is discouraged in write/delete heavy workloads, as these
42+
operations cause memory fragmentation that results in significantly degraded performance.
4643

4744
.. tip::
4845

49-
Note that this adapter's CRUD operations are specific to the PHP SAPI it is running
50-
under. This means adding a cache item using the CLI will not result in the item
51-
appearing under FPM. Likewise, deletion of an item using CGI will not result in the
52-
item being deleted under the CLI.
46+
This adapter's CRUD operations are specific to the PHP SAPI it is running under. This
47+
means cache operations (such as additions, deletions, etc) using the CLI will not be
48+
available under the FPM or CGI SAPIs.
5349

54-
.. _`APCu extension`: https://pecl.php.net/package/APCu
50+
.. _`APCu extension`: https://pecl.php.net/package/APCu

components/cache/adapters/chain_adapter.rst

+32-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
single: Cache Pool
33
single: Chain Cache
44

5+
.. _component-cache-chain-adapter:
6+
57
Chain Cache Adapter
68
===================
79

8-
This adapter allows to combine any number of the other available cache adapters.
9-
Cache items are fetched from the first adapter which contains them and cache items are
10-
saved in all the given adapters. This offers a simple way of creating a layered cache.
10+
This adapter allows combining any number of the other
11+
:ref:`available cache adapters <component-cache-creating-cache-pools>`. Cache items are
12+
fetched from the first adapter containing them and cache items are saved to all the
13+
given adapters. This exposes a simple and efficient method for creating a layered cache.
1114

12-
This adapter expects an array of adapters as its first parameter, and optionally a
13-
maximum cache lifetime as its second parameter::
15+
The ChainAdapter must be provided an array of adapters and optionally a maximum cache
16+
lifetime as its constructor arguments::
1417

1518
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1619

@@ -26,7 +29,7 @@ maximum cache lifetime as its second parameter::
2629
.. note::
2730

2831
When an item is not found in the first adapter but is found in the next ones, this
29-
adapter ensures that the fetched item is saved in all the adapters where it was
32+
adapter ensures that the fetched item is saved to all the adapters where it was
3033
previously missing.
3134

3235
The following example shows how to create a chain adapter instance using the fastest and
@@ -41,3 +44,26 @@ slowest storage engines, :class:`Symfony\\Component\\Cache\\Adapter\\ApcuAdapter
4144
new ApcuAdapter(),
4245
new FilesystemAdapter(),
4346
));
47+
48+
When calling this adapter's :method:`Symfony\\Component\\Cache\\ChainAdapter::prune` method,
49+
the call is deligated to all its compatibe cache adapters. It is safe to mix both adapters
50+
that *do* and do *not* implement :class:`Symfony\\Component\\Cache\\PruneableInterface`, as
51+
incompatible adapters are silently ignored::
52+
53+
use Symfony\Component\Cache\Adapter\ApcuAdapter;
54+
use Symfony\Component\Cache\Adapter\ChainAdapter;
55+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
56+
57+
$cache = new ChainAdapter(array(
58+
new ApcuAdapter(), // does NOT implement PruneableInterface
59+
new FilesystemAdapter(), // DOES implement PruneableInterface
60+
));
61+
62+
// prune will proxy the call to FilesystemAdapter while silently skipping ApcuAdapter
63+
$cache->prune();
64+
65+
.. note::
66+
67+
Since Symfony 3.4, this adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
68+
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
69+
calling its ``prune()`` method.

components/cache/adapters/filesystem_adapter.rst

+31-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
single: Cache Pool
33
single: Filesystem Cache
44

5+
.. _component-cache-filesystem-adapter:
6+
57
Filesystem Cache Adapter
68
========================
79

8-
This adapter is useful when you want to improve the application performance but
9-
can't install tools like APCu or Redis on the server. This adapter stores the
10-
contents as regular files in a set of directories on the local file system.
10+
This adapter offers improved application performance for those who cannot install
11+
tools like :ref:`APCu <apcu-adapter>` or :ref:`Redis <redis-adapter>` in their
12+
environment. It stores the cache item expiration and content as regular files in
13+
a collection of directories on a locally mounted filesystem.
14+
15+
.. tip::
16+
17+
The performance of this adapter can be greatly increased by utilizing a
18+
temporary, in-memory filesystem, such as `tmpfs`_ on Linux, or one of the
19+
many other `RAM disk solutions`_ available.
1120

12-
This adapter can optionally be provided a namespace, default cache lifetime, and
13-
directory path, as its first, second, and third parameters::
21+
The FilesystemAdapter can optionally be provided a namespace, default cache lifetime,
22+
and cache root path as constructor parameters::
1423

1524
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1625

@@ -30,9 +39,21 @@ directory path, as its first, second, and third parameters::
3039
$directory = null
3140
);
3241

33-
.. tip::
42+
.. caution::
43+
44+
The overhead of filesystem IO often makes this adapter one of the *slower*
45+
choices. If throughput is paramount, the in-memory adapters
46+
(:ref:`Apcu <apcu-adapter>`, :ref:`Memcached <memcached-adapter>`, and
47+
:ref:`Redis <redis-adapter>`) or the database adapters
48+
(:ref:`Doctrine <doctrine-adapter>` and :ref:`PDO <pdo-doctrine-adapter>`)
49+
are recommended.
50+
51+
.. note::
52+
53+
Since Symfony 3.4, this adapter implements
54+
:class:`Symfony\\Component\\Cache\\PruneableInterface`, enabling manual
55+
:ref:`pruning of expired cache items <component-cache-cache-pool-prune>` by
56+
calling its ``prune()`` method.
3457

35-
This adapter is generally the *slowest* due to the overhead of file IO. If throughput is paramount,
36-
the in-memory adapters (such as :ref:`APCu <apcu-adapter>`, :ref:`Memcached <memcached-adapter>`,
37-
and :ref:`Redis <redis-adapter>`) or the database adapters (such as
38-
:ref:`Doctrine <doctrine-adapter>` and :ref:`PDO & Doctrine <pdo-doctrine-adapter>`) are recommended.
58+
.. _`tmpfs`: https://wiki.archlinux.org/index.php/tmpfs
59+
.. _`RAM disk solutions`: https://en.wikipedia.org/wiki/List_of_RAM_drive_software

components/cache/adapters/pdo_doctrine_dbal_adapter.rst

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ third, and forth parameters::
3636
When passed a `Data Source Name (DSN)`_ string (instead of a database connection
3737
class instance), the connection will be lazy-loaded when needed.
3838

39+
.. note::
40+
41+
Since Symfony 3.4, this adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
42+
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
43+
calling its ``prune()`` method.
44+
3945
.. _`PDO`: http://php.net/manual/en/class.pdo.php
4046
.. _`Doctrine DBAL Connection`: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php
4147
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name

components/cache/adapters/php_array_cache_adapter.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This adapter is a highly performant way to cache static data (e.g. application c
99
that is optimized and preloaded into OPcache memory storage::
1010

1111
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
12-
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
12+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1313

1414
// somehow, decide it's time to warm up the cache!
1515
if ($needsWarmup) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.. index::
2+
single: Cache Pool
3+
single: PHP Files Cache
4+
5+
.. _component-cache-files-adapter:
6+
7+
Php Files Cache Adapter
8+
=======================
9+
10+
Similarly to :ref:`Filesystem Adapter <component-cache-filesystem-adapter>`, this cache
11+
implementation writes cache entries out to disk, but unlike the Filesystem cache adapter,
12+
the PHP Files cache adapter writes and reads back these cache files *as native PHP code*.
13+
For example, caching the value ``array('my', 'cached', 'array')`` will write out a cache
14+
file similar to the following::
15+
16+
<?php return array(
17+
18+
// the cache item expiration
19+
0 => 9223372036854775807,
20+
21+
// the cache item contents
22+
1 => array (
23+
0 => 'my',
24+
1 => 'cached',
25+
2 => 'array',
26+
),
27+
28+
);
29+
30+
.. note::
31+
32+
As cache items are included and parsed as native PHP code and due to the way `OPcache`_
33+
handles file includes, this adapter has the potential to be much faster than other
34+
filesystem-based caches.
35+
36+
The PhpFilesAdapter can optionally be provided a namespace, default cache lifetime, and cache
37+
directory path as constructor arguments::
38+
39+
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
40+
41+
$cache = new PhpFilesAdapter(
42+
43+
// a string used as the subdirectory of the root cache directory, where cache
44+
// items will be stored
45+
$namespace = '',
46+
47+
// the default lifetime (in seconds) for cache items that do not define their
48+
// own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
49+
// until the files are deleted)
50+
$defaultLifetime = 0,
51+
52+
// the main cache directory (the application needs read-write permissions on it)
53+
// if none is specified, a directory is created inside the system temporary directory
54+
$directory = null
55+
);
56+
57+
.. note::
58+
59+
Since Symfony 3.4, this adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
60+
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
61+
calling its ``prune()`` method.
62+
63+
.. _`OPcache`: http://php.net/manual/en/book.opcache.php

components/cache/cache_invalidation.rst

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ your fronts and have very fast invalidation checks::
7777
new RedisAdapter('redis://localhost')
7878
);
7979

80+
.. note::
81+
82+
Since Symfony 3.4, :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter`
83+
implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
84+
enabling manual
85+
:ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
86+
calling its :method:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter::prune`
87+
method (assuming the wrapped adapter itself implements
88+
:class:`Symfony\\Component\\Cache\\PruneableInterface`).
89+
8090
.. _cache-component-expiration:
8191

8292
Using Cache Expiration

components/cache/cache_pools.rst

+66-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ are independent from the actual cache implementation. Therefore, applications
2020
can keep using the same cache pool even if the underlying cache mechanism
2121
changes from a file system based cache to a Redis or database based cache.
2222

23+
.. _component-cache-creating-cache-pools:
24+
2325
Creating Cache Pools
2426
--------------------
2527

@@ -124,8 +126,9 @@ when all items are successfully deleted)::
124126

125127
.. tip::
126128

127-
If the Cache component is used inside a Symfony application, you can remove
128-
all the items of a given cache pool with the following command:
129+
If the cache component is used inside a Symfony application, you can remove
130+
*all items* from the *given pool(s)* using the following command (which resides within
131+
the :ref:`framework bundle <framework-bundle-configuration>`):
129132

130133
.. code-block:: terminal
131134
@@ -137,4 +140,64 @@ when all items are successfully deleted)::
137140
# clears the "cache.validation" and "cache.app" pool
138141
$ php bin/console cache:pool:clear cache.validation cache.app
139142
140-
.. _`Doctrine Cache`: https://github.com/doctrine/cache
143+
.. _component-cache-cache-pool-prune:
144+
145+
Pruning Cache Items
146+
-------------------
147+
148+
Some cache pools do not include an automated mechanism for pruning expired cache items.
149+
For example, the :ref:`FilesystemAdaper <component-cache-filesystem-adapter>` cache
150+
does not remove expired cache items *until an item is explicitly requested and determined to
151+
be expired*, for example, via a call to :method:`Psr\\Cache\\CacheItemPoolInterface::getItem`.
152+
Under certain workloads, this can cause stale cache entries to persist well past their
153+
expiration, resulting in a sizable consumption of wasted disk or memory space from excess,
154+
expired cache items.
155+
156+
This shortcomming has been solved through the introduction of
157+
:class:`Symfony\\Component\\Cache\\PruneableInterface`, which defines the abstract method
158+
:method:`Symfony\\Component\\Cache\\PruneableInterface::prune`. The
159+
:ref:`ChainAdapter <component-cache-chain-adapter>`,
160+
:ref:`FilesystemAdaper <component-cache-filesystem-adapter>`,
161+
:ref:`PdoAdapter <pdo-doctrine-adapter>`, and
162+
:ref:`PhpFilesAdapter <component-cache-files-adapter>` all implement this new interface,
163+
allowing manual removal of stale cache items::
164+
165+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
166+
167+
$cache = new FilesystemAdapter('app.cache');
168+
// ... do some set and get operations
169+
$cache->prune();
170+
171+
The :ref:`ChainAdapter <component-cache-chain-adapter>` implementation does not directly
172+
contain any pruning logic itself. Instead, when calling the chain adapter's
173+
:method:`Symfony\\Component\\Cache\\ChainAdapter::prune` method, the call is delegated to all
174+
its compatibe cache adapters (and those that do not implement ``PruneableInterface`` are
175+
silently ignored)::
176+
177+
use Symfony\Component\Cache\Adapter\ApcuAdapter;
178+
use Syfmony\Component\Cache\Adapter\ChainAdapter;
179+
use Syfmony\Component\Cache\Adapter\FilesystemAdapter;
180+
use Syfmony\Component\Cache\Adapter\PdoAdapter;
181+
use Syfmony\Component\Cache\Adapter\PhpFilesAdapter;
182+
183+
$cache = new ChainAdapter(array(
184+
new ApcuAdapter(), // does NOT implement PruneableInterface
185+
new FilesystemAdapter(), // DOES implement PruneableInterface
186+
new PdoAdapter(), // DOES implement PruneableInterface
187+
new PhpFilesAdapter(), // DOES implement PruneableInterface
188+
// ...
189+
));
190+
191+
// prune will proxy the call to PdoAdapter, FilesystemAdapter and PhpFilesAdapter,
192+
// while silently skipping ApcuAdapter
193+
$cache->prune();
194+
195+
.. tip::
196+
197+
If the cache component is used inside a Symfony application, you can prune
198+
*all items* from *all pools* using the following command (which resides within
199+
the :ref:`framework bundle <framework-bundle-configuration>`):
200+
201+
.. code-block:: terminal
202+
203+
$ php bin/console cache:pool:prune

components/process.rst

+24
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,29 @@ stream resources or Traversable objects as argument. As shown in the above examp
240240
you need to explicitly call the :method:`Symfony\\Component\\Process\\InputStream::close`
241241
method when you are done writing to the standard input of the subprocess.
242242

243+
Using PHP Streams as the Standard Input of a Process
244+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245+
246+
The input of a process can also be defined using `PHP streams`_::
247+
248+
$stream = fopen('php://temporary', 'w+');
249+
250+
$process = new Process('cat');
251+
$process->setInput($stream);
252+
$process->start();
253+
254+
fwrite($stream, 'foo');
255+
256+
// ... read process output or do other things
257+
258+
fwrite($stream, 'bar');
259+
fclose($stream);
260+
261+
$process->wait();
262+
263+
// will echo: 'foobar'
264+
echo $process->getOutput();
265+
243266
Stopping a Process
244267
------------------
245268

@@ -394,3 +417,4 @@ Use :method:`Symfony\\Component\\Process\\Process::disableOutput` and
394417
.. _`pid`: https://en.wikipedia.org/wiki/Process_identifier
395418
.. _`PHP Documentation`: http://php.net/manual/en/pcntl.constants.php
396419
.. _Packagist: https://packagist.org/packages/symfony/process
420+
.. _`PHP streams`: http://www.php.net/manual/en/book.stream.php

components/serializer.rst

-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ You are now able to serialize only attributes in the groups you want::
322322
);
323323
// $obj2 = MyObj(foo: 'foo', bar: 'bar')
324324

325-
.. include:: /_includes/_rewrite_rule_tip.rst.inc
326-
327325
.. _ignoring-attributes-when-serializing:
328326

329327
Selecting Specific Attributes

0 commit comments

Comments
 (0)