Skip to content

Commit 1b6cb69

Browse files
committed
Covering two missing adapters introduced in 3.2
1 parent 32994da commit 1b6cb69

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

components/cache/cache_pools.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ contents as regular files in a set of directories on the local file system::
5858
$directory = null
5959
);
6060

61+
Php Files Cache Adapter
62+
~~~~~~~~~~~~~~~~~~~~~~~
63+
64+
This adapter is very similar to the Filesystem adapter, except that the saving creates
65+
a ``.php`` file, which is included on fetch (allowing the file to me saved in OpCache)::
66+
67+
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
68+
69+
$cache = new PhpFilesAdapter(
70+
// the subdirectory of the main cache directory where cache items are stored
71+
$namespace = '',
72+
// in seconds; applied to cache items that don't define their own lifetime
73+
// 0 means to store the cache items indefinitely (i.e. until the files are deleted)
74+
$defaultLifetime = 0,
75+
// the main cache directory (the application needs read-write permissions on it)
76+
// if none is specified, a directory is created inside the system temporary directory
77+
$directory = null
78+
);
79+
6180
APCu Cache Adapter
6281
~~~~~~~~~~~~~~~~~~
6382

@@ -189,6 +208,41 @@ This adapter also defines two optional arguments called ``namespace`` (default:
189208
``''``) and ``defaultLifetime`` (default: ``0``) and adapts them to make them
190209
work in the underlying Doctrine cache.
191210

211+
Php Array Cache Adapter
212+
~~~~~~~~~~~~~~~~~~~~~~~
213+
214+
This adapter is a highly performant way to cache static data (e.g. application configuration)
215+
that is optimized and preloaded into OpCache memory storage::
216+
217+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
218+
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
219+
220+
// somehow, decide it's time to warmup the cache!
221+
if ($needsWarmup) {
222+
// some static values
223+
$values = array(
224+
'stats.num_products' => 4711,
225+
'stats.num_users' => 1356,
226+
);
227+
228+
$cache = new PhpArrayAdapter(
229+
// single file where values are cached
230+
__DIR__ . '/somefile.cache',
231+
// a backup adapter, if you set values after warmup
232+
new FilesystemAdapter()
233+
);
234+
$cache->warmUp($values);
235+
}
236+
237+
// ... then, use the cache!
238+
$cacheItem = $cache->getItem('stats.num_users');
239+
echo $cacheItem->get();
240+
241+
.. note::
242+
243+
This adapter requires PHP 7.x and should be used with the php.ini setting
244+
``opcache.enable`` on.
245+
192246
Looking for Cache Items
193247
-----------------------
194248

0 commit comments

Comments
 (0)