Skip to content

[Cache] Update for 4.3 #11485

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 2 commits into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions components/cache/psr6_psr16_adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ standard, but need to pass it to an object that expects a :ref:`PSR-6 <cache-com
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.

.. versionadded:: 4.3

The ``Psr16Adapter`` and ``Psr16Cache`` classes mentioned below were added in Symfony 4.3.

Using a PSR-16 Cache Object as a PSR-6 Cache
--------------------------------------------

Expand All @@ -33,17 +37,15 @@ example::

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
:class:`Symfony\\Component\\Cache\\Adapter\\Psr16Adapter` class for exactly
this use-case::

use Symfony\Component\Cache\Adapter\SimpleCacheAdapter;
use Symfony\Component\Cache\Simple\FilesystemCache;
use Symfony\Component\Cache\Adapter\Psr16Adapter;

// the PSR-16 cache object that you want to use
$psr16Cache = new FilesystemCache();
// $psr16Cache is the PSR-16 object that you want to use as a PSR-6 one

// a PSR-6 cache that uses your cache internally!
$psr6Cache = new SimpleCacheAdapter($psr16Cache);
$psr6Cache = new Psr16Adapter($psr16Cache);

// now use this wherever you want
$githubApiClient = new GitHubApiClient($psr6Cache);
Expand All @@ -70,11 +72,11 @@ example::

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
:class:`Symfony\\Component\\Cache\\Psr16Cache` class for exactly
this use-case::

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Simple\Psr6Cache;
use Symfony\Component\Cache\Psr16Cache;

// the PSR-6 cache object that you want to use
$psr6Cache = new FilesystemAdapter();
Expand Down