-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Covering two missing Cache adapters introduced in 3.2 #7424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,25 @@ contents as regular files in a set of directories on the local file system:: | |
$directory = null | ||
); | ||
|
||
Php Files Cache Adapter | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
This adapter is very similar to the Filesystem adapter, except that the saving creates | ||
a ``.php`` file, which is included on fetch (allowing the file to be saved in OPcache):: | ||
|
||
use Symfony\Component\Cache\Adapter\PhpFilesAdapter; | ||
|
||
$cache = new PhpFilesAdapter( | ||
// the subdirectory of the main cache directory where cache items are stored | ||
$namespace = '', | ||
// in seconds; applied to cache items that don't define their own lifetime | ||
// 0 means to store the cache items indefinitely (i.e. until the files are deleted) | ||
$defaultLifetime = 0, | ||
// the main cache directory (the application needs read-write permissions on it) | ||
// if none is specified, a directory is created inside the system temporary directory | ||
$directory = null | ||
); | ||
|
||
APCu Cache Adapter | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
|
@@ -189,6 +208,41 @@ This adapter also defines two optional arguments called ``namespace`` (default: | |
``''``) and ``defaultLifetime`` (default: ``0``) and adapts them to make them | ||
work in the underlying Doctrine cache. | ||
|
||
Php Array Cache Adapter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
This adapter is a highly performant way to cache static data (e.g. application configuration) | ||
that is optimized and preloaded into OPcache memory storage:: | ||
|
||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter; | ||
use Symfony\Component\Cache\Adapter\PhpFilesAdapter; | ||
|
||
// somehow, decide it's time to warm up the cache! | ||
if ($needsWarmup) { | ||
// some static values | ||
$values = array( | ||
'stats.num_products' => 4711, | ||
'stats.num_users' => 1356, | ||
); | ||
|
||
$cache = new PhpArrayAdapter( | ||
// single file where values are cached | ||
__DIR__ . '/somefile.cache', | ||
// a backup adapter, if you set values after warmup | ||
new FilesystemAdapter() | ||
); | ||
$cache->warmUp($values); | ||
} | ||
|
||
// ... then, use the cache! | ||
$cacheItem = $cache->getItem('stats.num_users'); | ||
echo $cacheItem->get(); | ||
|
||
.. note:: | ||
|
||
This adapter requires PHP 7.x and should be used with the php.ini setting | ||
``opcache.enable`` on. | ||
|
||
Looking for Cache Items | ||
----------------------- | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Php Files
->PHP Files
? (after all, PHP is an acronym)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave this - I did it because the name of the class is PhpFilesAdapter... but I could see it either way (I would normally 100% agree)