8000 Adding documentation about the simple cache PSR-16 implementation by weaverryan · Pull Request #7417 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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
wants to merge 8 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reversing my 6-16 - got myself totally confused :)
  • Loading branch information
weaverryan committed Jan 27, 2017
commit 9887c98421675ee847fd58f025513e3ad302cbbd
36 changes: 18 additions & 18 deletions components/cache/psr6_psr16_adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ standard, but need to pass it to an object that expects a :ref:`PSR-6 <>`
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-6 Cache Object as a PSR-16 Cache
Using a PSR-16 Cache Object as a PSR-6 Cache
--------------------------------------------

Suppose you want to work with a class that requires a PSR-16 Cache pool object. For
Suppose you want to work with a class that requires a PSR-6 Cache pool object. For
example::

use Psr\Cache\CacheItemPoolInterface;
Expand All @@ -24,34 +24,34 @@ example::
{
// ...

// this requires a PSR-16 cache object
// this requires a PSR-6 cache object
public function __construct(CacheItemPoolInterface $cachePool)
{
// ...
}
}

But, you already have a PSR-6 cache object, and you'd like to pass this to the class
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-6 cache object that you want to use
$psr6Cache = new FilesystemCache();
// the PSR-16 cache object that you want to use
$psr16Cache = new FilesystemCache();

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

// now use this wherever you want
$githubApiClient = new GitHubApiClient($psr16Cache);
$githubApiClient = new GitHubApiClient($psr6Cache);

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

Suppose you want to work with a class that requires a PSR-6 Cache object. For
Suppose you want to work with a class that requires a PSR-16 Cache object. For
example::

use Psr\SimpleCache\CacheInterface;
Expand All @@ -61,26 +61,26 @@ example::
{
// ...

// this requires a PSR-6 cache object
// this requires a PSR-16 cache object
public function __construct(CacheInterface $cache)
{
// ...
}
}

But, you already have a PSR-16 cache pool object, and you'd like to pass this to
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-16 cache object that you want to use
$psr16Cache = new FilesystemAdapter();
// the PSR-6 cache object that you want to use
$psr6Cache = new FilesystemAdapter();

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

// now use this wherever you want
$githubApiClient = new GitHubApiClient($psr6Cache);
$githubApiClient = new GitHubApiClient($psr16Cache);
0