Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2481c4

Browse files
committed
feature#7424 Covering two missing Cache adapters introduced in 3.2 (weaverryan)
This PR was merged into the 3.2 branch.Discussion----------Covering two missing Cache adapters introduced in 3.2Hi guys!These are 2 missing adapters that were introduced in 3.2!symfony/symfony#18894 andsymfony/symfony#18823Cheers!Commits-------a3e69e2 Tweaks based on feedback!1b6cb69 Covering two missing adapters introduced in 3.2
2 parents32994da +a3e69e2 commitc2481c4

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 be 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 warm up 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)

[8]ページ先頭

©2009-2025 Movatter.jp