@@ -45,42 +45,30 @@ This documentation does not cover every single cache driver included
4545with Doctrine. For an up-to-date-list, see the
4646`cache directory on GitHub <https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache >`_.
4747
48- APC
49- ~~~
50-
51- In order to use the APC cache driver you must have it compiled and
52- enabled in your php.ini. You can read about APC
53- `in the PHP Documentation <http://us2.php.net/apc >`_. It will give
54- you a little background information about what it is and how you
55- can use it as well as how to install it.
56-
57- Below is a simple example of how you could use the APC cache driver
58- by itself.
59-
60- .. code-block :: php
61-
62- <?php
63- $cacheDriver = new \Doctrine\Common\Cache\ApcCache();
64- $cacheDriver->save('cache_id', 'my_data');
48+ PhpFileCache
49+ ~~~~~~~~~~~~
6550
66- APCu
67- ~~~~
51+ The preferred cache driver for metadata and query caches is ``PhpFileCache ``.
52+ This driver serializes cache items and writes them to a file. This allows for
53+ opcode caching to be used and provides high performance in most scenarios.
6854
69- In order to use the APCu cache driver you must have it compiled and
70- enabled in your php.ini. You can read about APCu
71- `in the PHP Documentation <http://us2.php.net/apcu >`_. It will give
72- you a little background information about what it is and how you
73- can use it as well as how to install it.
55+ In order to use the ``PhpFileCache `` driver it must be able to write to
56+ a directory.
7457
75- Below is a simple example of how you could use the APCu cache driver
76- by itself.
58+ Below is an example of how to use the ``PhpFileCache `` driver by itself.
7759
7860.. code-block :: php
7961
8062 <?php
81- $cacheDriver = new \Doctrine\Common\Cache\ApcuCache();
63+ $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache(
64+ '/path/to/writable/directory'
65+ );
8266 $cacheDriver->save('cache_id', 'my_data');
8367
68+ The PhpFileCache is not distributed across multiple machines if you are running
69+ your application in a distributed setup. This is ok for the metadata and query
70+ cache but is not a good approach for the result cache.
71+
8472Memcache
8573~~~~~~~~
8674
@@ -128,24 +116,6 @@ driver by itself.
128116 $cacheDriver->setMemcached($memcached);
129117 $cacheDriver->save('cache_id', 'my_data');
130118
131- Xcache
132- ~~~~~~
133-
134- In order to use the Xcache cache driver you must have it compiled
135- and enabled in your php.ini. You can read about Xcache
136- `here <http://xcache.lighttpd.net/ >`_. It will give you a little
137- background information about what it is and how you can use it as
138- well as how to install it.
139-
140- Below is a simple example of how you could use the Xcache cache
141- driver by itself.
142-
143- .. code-block :: php
144-
145- <?php
146- $cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
147- $cacheDriver->save('cache_id', 'my_data');
148-
149119 Redis
150120~~~~~
151121
@@ -306,8 +276,11 @@ use on your ORM configuration.
306276.. code-block :: php
307277
308278 <?php
279+ $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache(
280+ '/path/to/writable/directory'
281+ );
309282 $config = new \Doctrine\ORM\Configuration();
310- $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcuCache() );
283+ $config->setQueryCacheImpl($cacheDriver );
311284
312285 Result Cache
313286~~~~~~~~~~~~
@@ -320,7 +293,11 @@ cache implementation.
320293.. code-block :: php
321294
322295 <?php
323- $config->setResultCacheImpl(new \Doctrine\Common\Cache\ApcuCache());
296+ $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache(
297+ '/path/to/writable/directory'
298+ );
299+ $config = new \Doctrine\ORM\Configuration();
300+ $config->setResultCacheImpl($cacheDriver);
324301
325302 Now when you're executing DQL queries you can configure them to use
326303the result cache.
@@ -337,7 +314,11 @@ result cache driver.
337314.. code-block :: php
338315
339316 <?php
340- $query->setResultCacheDriver(new \Doctrine\Common\Cache\ApcuCache());
317+ $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache(
318+ '/path/to/writable/directory'
319+ );
320+ $config = new \Doctrine\ORM\Configuration();
321+ $query->setResultCacheDriver($cacheDriver);
341322
342323 .. note ::
343324
@@ -389,7 +370,11 @@ first.
389370.. code-block :: php
390371
391372 <?php
392- $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcuCache());
373+ $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache(
374+ '/path/to/writable/directory'
375+ );
376+ $config = new \Doctrine\ORM\Configuration();
377+ $config->setMetadataCacheImpl($cacheDriver);
393378
394379 Now the metadata information will only be parsed once and stored in
395380the cache driver.
@@ -425,6 +410,12 @@ To clear the result cache use the ``orm:clear-cache:result`` task.
425410 All these tasks accept a ``--flush `` option to flush the entire
426411contents of the cache instead of invalidating the entries.
427412
413+ .. note ::
414+
415+ None of these tasks will work with APC, APCu, or XCache drivers
416+ because the memory that the cache is stored in is only accessible
417+ to the webserver.
418+
428419Cache Chaining
429420--------------
430421
0 commit comments