-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Adding documentation about the simple cache PSR-16 implementation #7417
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d9fb6da
Adding documentation about the simple cache PSR-16 implementation
weaverryan 96ed2dd
Adding docs about converting between PSR6 and PSR16
weaverryan aa2354d
Fixing based on feedback!
weaverryan 9887c98
Reversing my 6-16 - got myself totally confused :)
weaverryan 7af448b
Tweaks after feedback!
weaverryan 14dba61
Finishing my todo
weaverryan e81c887
Fixing another bad link
weaverryan d9b9a04
Adding more missing links
weaverryan 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
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
.. index:: | ||
single: Cache | ||
single: Performance | ||
single: Components; Cache | ||
|
||
Adapters For Interoperability between PSR-6 and PSR-16 Cache | ||
============================================================ | ||
|
||
Sometimes, you may have a Cache object that implements the :ref:`PSR-16 <cache-component-psr16-caching>` | ||
standard, but need to pass it to an object that expects a :ref:`PSR-6 <cache-component-psr6-caching>` | ||
cache adapter. Or, you might have the opposite situation. The cache component contains | ||
two classes for bidirectional interoperability between PSR-6 and PSR-16 caches. | ||
|
||
Using a PSR-16 Cache Object as a PSR-6 Cache | ||
-------------------------------------------- | ||
|
||
Suppose you want to work with a class that requires a PSR-6 Cache pool object. For | ||
example:: | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
// just a made-up class for the example | ||
class GitHubApiClient | ||
{ | ||
// ... | ||
|
||
// this requires a PSR-6 cache object | ||
public function __construct(CacheItemPoolInterface $cachePool) | ||
{ | ||
// ... | ||
} | ||
} | ||
|
||
But, you already have a PSR-16 cache object, and you'd like to pass this to the class | ||
instead. No problem! The Cache component provides the | ||
:class:`Symfony\\Component\\Cache\\Adapter\\SimpleCacheAdapter` class for exactly | ||
this use-case:: | ||
|
||
use Symfony\Component\Cache\Simple\FilesystemCache; | ||
use Symfony\Component\Cache\Adapter\SimpleCacheAdapter | ||
|
||
// the PSR-16 cache object that you want to use | ||
$psr16Cache = new FilesystemCache(); | ||
|
||
// a PSR-6 cache that uses your cache internally! | ||
$psr6Cache = new SimpleCacheAdapter($psr16Cache); | ||
|
||
// now use this wherever you want | ||
$githubApiClient = new GitHubApiClient($psr6Cache); | ||
|
||
Using a PSR-6 Cache Object as a PSR-16 Cache | ||
-------------------------------------------- | ||
|
||
Suppose you want to work with a class that requires a PSR-16 Cache object. For | ||
example:: | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
// just a made-up class for the example | ||
class GitHubApiClient | ||
{ | ||
// ... | ||
|
||
// this requires a PSR-16 cache object | ||
public function __construct(CacheInterface $cache) | ||
{ | ||
// ... | ||
} | ||
} | ||
|
||
But, you already have a PSR-6 cache pool object, and you'd like to pass this to | ||
the class instead. No problem! The Cache component provides the | ||
:class:`Symfony\\Component\\Cache\\Simple\\Psr6Cache` class for exactly | ||
this use-case:: | ||
|
||
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | ||
use Symfony\Component\Cache\Simple\Psr6Cache; | ||
|
||
// the PSR-6 cache object that you want to use | ||
$psr6Cache = new FilesystemAdapter(); | ||
|
||
// a PSR-16 cache that uses your cache internally! | ||
$psr16Cache = new Psr6Cache($psr6Cache); | ||
|
||
// now use this wherever you want | ||
$githubApiClient = new GitHubApiClient($psr16Cache); |
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.
@nicolas-grekas Is this small section accurate? Everything else is straightforward - I just wanted you to check this one spot! Thanks!