@@ -58,6 +58,25 @@ contents as regular files in a set of directories on the local file system::
58
58
$directory = null
59
59
);
60
60
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
+
61
80
APCu Cache Adapter
62
81
~~~~~~~~~~~~~~~~~~
63
82
@@ -189,6 +208,41 @@ This adapter also defines two optional arguments called ``namespace`` (default:
189
208
``'' ``) and ``defaultLifetime `` (default: ``0 ``) and adapts them to make them
190
209
work in the underlying Doctrine cache.
191
210
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
+
192
246
Looking for Cache Items
193
247
-----------------------
194
248
0 commit comments