From d9fb6da3df7d59b007c6ca4a6d05d2d973968130 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 26 Jan 2017 06:43:28 -0500 Subject: [PATCH 1/8] Adding documentation about the simple cache PSR-16 implementation --- components/cache.rst | 130 +++++++++++++++++++++++++++---- components/cache/cache_pools.rst | 69 +++++++++++++++- 2 files changed, 182 insertions(+), 17 deletions(-) diff --git a/components/cache.rst b/components/cache.rst index e7a44bb05e3..b1b8da1f69d 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -6,13 +6,17 @@ The Cache Component =================== - The Cache component provides an extended `PSR-6`_ implementation for adding - cache to your applications. It is designed to have a low overhead and it - ships with ready to use adapters for the most common caching backends. + The Cache component provides an extended `PSR-6`_ implementation as well as + a `PSR-16`_ "Simple Cache" implementation for adding cache to your applications. + It is designed to have a low overhead and it ships with ready to use adapters + for the most common caching backends. .. versionadded:: 3.1 The Cache component was introduced in Symfony 3.1. +.. versionadded:: 3.3 + The PSR-16 "Simple Cache" implementation was introduced in Symfony 3.3. + Installation ------------ @@ -21,11 +25,27 @@ You can install the component in 2 different ways: * :doc:`Install it via Composer ` (``symfony/cache`` on `Packagist`_); * Use the official Git repository (https://github.com/symfony/cache). -Key Concepts ------------- +Cache (PSR-6) Versus Simple Cache (PSR-16) +------------------------------------------ + +This component includes *two* different approaches to caching: + +:ref:`PSR-6 Caching `: + A fully-featured cache system, which includes cache "pools", more advanced + cache "items", and :ref:`cache tagging for invalidation `. + +:ref:`PSR-16 Simple Caching `: + A simple way to store, fetch and remove items from a cache. + +Both methods support the *same* cache adapters and will give you very similar performance. + +.. _cache-component-psr6-caching: -Before starting to use the Cache component, it's important that you learn the -meaning of some key concepts: +More Advanced Caching (PSR-6) +----------------------------- + +To use the more-advanced, PSR-6 Caching abilities, you'll need to learn its key +concepts: **Item** A single unit of information stored as a key/value pair, where the key is @@ -39,11 +59,11 @@ meaning of some key concepts: filesystem, in a database, etc. The component provides several ready to use adapters for common caching backends (Redis, APCu, etc.) -Basic Usage ------------ +Basic Usage (PSR-6) +------------------- -This component is an implementation of `PSR-6`_, which means that its basic API -is the same as defined in the standard. Before starting to cache information, +This part of the component is an implementation of `PSR-6`_, which means that its +basic API is the same as defined in the standard. Before starting to cache information, create the cache pool using any of the built-in adapters. For example, to create a filesystem-based cache, instantiate :class:`Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter`:: @@ -71,8 +91,10 @@ Now you can create, retrieve, update and delete items using this cache pool:: // remove the cache item $cache->deleteItem('stats.num_products'); -Advanced Usage --------------- +For a list of all of the supported adapters, see :doc:`/components/cache/cache_pools`. + +Advanced Usage (PSR-6) +---------------------- .. toctree:: :glob: @@ -80,5 +102,87 @@ Advanced Usage cache/* +.. _cache-component-psr16-caching: + +Simple Caching (PSR-16) +----------------------- + +This part of the component is an implementation of `PSR-16`_, which means that its +basic API is the same as defined in the standard. First, create a cache object from +one of the built-in cache clases. For example, to create a filesystem-based cache, +instantiate :class:`Symfony\\Component\\Cache\\Simple\\FilesystemCache`:: + + use Symfony\Component\Cache\Simple\FilesystemCache; + + $cache = new FilesystemCache(); + +Now you can create, retrieve, update and delete items using this object:: + + // save a new item in the cache + $cache->set('stats.num_products', 4711); + + // or set it with a custom ttl + // $cache->set('stats.num_products', 4711, 3600); + + // retrieve the cache item + if (!$cache->has('stats.num_products')) { + // ... item does not exists in the cache + } + + // retrieve the value stored by the item + $numProducts = $cache->get('stats.num_products'); + + // or specify a default value, if the key doesn't exist + // $numProducts = $cache->get('stats.num_products', 100); + + // remove the cache key + $cache->deleteItem('stats.num_products'); + + // clear *all* cache keys + $cache->clear(); + +You can also work with multiple items at once:: + + $cache->setMultiple([ + 'stats.num_products' => 4711, + 'stats.num_users' => 1356, + ]); + + $stats = $cache->getMultiple([ + 'stats.num_products', + 'stats.num_users', + ]); + + $cache->deleteMultiple([ + 'stats.num_products', + 'stats.num_users', + ]); + +Available Simple Cache (PSR-16) Classes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following cache adapters are available: + +.. tip:: + + To find out more about each of these classes, you can read th + :doc:`PSR-6 Cache Pool ` page. These "Simple" + (PSR-16) cache classes aren't identical to the PSR-6 Adapters on that page, but + each share constructor arguments and use-cases. + +* :class:`Symfony\\Component\\Cache\\Simple\\ApcuCache` +* :class:`Symfony\\Component\\Cache\\Simple\\ArrayCache` +* :class:`Symfony\\Component\\Cache\\Simple\\ChainCache` +* :class:`Symfony\\Component\\Cache\\Simple\\DoctrineCache` +* :class:`Symfony\\Component\\Cache\\Simple\\FilesystemCache` +* :class:`Symfony\\Component\\Cache\\Simple\\MemcachedCache` +* :class:`Symfony\\Component\\Cache\\Simple\\NullCache` +* :class:`Symfony\\Component\\Cache\\Simple\\PdoCache` +* :class:`Symfony\\Component\\Cache\\Simple\\PhpArrayCache` +* :class:`Symfony\\Component\\Cache\\Simple\\PhpFilesCache` +* :class:`Symfony\\Component\\Cache\\Simple\\RedisCache` +* :class:`Symfony\\Component\\Cache\\Simple\\TraceableCache` + .. _`PSR-6`: http://www.php-fig.org/psr/psr-6/ +.. _`PSR-16`: http://www.php-fig.org/psr/psr-16/ .. _Packagist: https://packagist.org/packages/symfony/cache diff --git a/components/cache/cache_pools.rst b/components/cache/cache_pools.rst index f7fddbff78f..c9d51154355 100644 --- a/components/cache/cache_pools.rst +++ b/components/cache/cache_pools.rst @@ -5,8 +5,8 @@ single: Redis Cache single: PDO Cache, Doctrine DBAL Cache -Cache Pools -=========== +Cache Pools & Supported Adapters +================================ Cache Pools are the logical repositories of cache items. They perform all the common operations on items, such as saving them or looking for them. Cache pools @@ -88,8 +88,9 @@ This adapter stores the contents in the memory of a Redis server. Unlike the APC adapter, it's not limited to the shared memory of the current server, so you can store contents in a cluster of servers if needed. -It requires to have installed Redis and have created a connection that implements -the ``\Redis``, ``\RedisArray``, ``\RedisCluster`` or ``\Predis`` classes:: +Before you start, make sure you have Redis running and have created a connection +that implements the ``\Redis``, ``\RedisArray``, ``\RedisCluster`` or ``\Predis`` +classes:: use Symfony\Component\Cache\Adapter\RedisAdapter; @@ -108,6 +109,46 @@ helper allows creating a connection to a Redis server using a DSN configuration: $redisConnection = RedisAdapter::createConnection('redis://localhost'); + $cache = new RedisAdapter($redisConnection); + +See the method's docblock for more options. + +Memcached Cache Adapter +~~~~~~~~~~~~~~~~~~~~~~~ + +This adapter stores the contents into a set of `Memcached`_ servers. + +Before you start, make sure you have Memcached running and have created a +:phpclass:`Memcached` object:: + + use Symfony\Component\Cache\Adapter\MemcachedAdapter; + + $cache = new MemcachedAdapter( + // the object that stores a valid connection to your Memcached servers + \Memcached $client, + // the string prefixed to the keys of the items stored in this cache + $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 Memcached memory is deleted) + $defaultLifetime = 0 + ); + +The :method:`Symfony\\Component\\Cache\\Adapter\\Memcached::createConnection` +helper allows creating a connection to a pool of Memcached server using a DSN configuration:: + + $memcachedClient = MemcachedAdapter::createConnection( + 'memcached://user:pass@localhost?weight=33', + + // options, including username, password and Memcached::OPT_* options + ['persistent_id' => '_products_cache'] + ); + $memcachedClient = MemcachedAdapter::createConnection([ + array('192.168.1.100', 11211, 33), + array('192.168.1.101', 11211, 33) + ]); + + $cache = new MemcachedAdapter($memcachedClient); + See the method's docblock for more options. PDO & Doctrine DBAL Cache Adapter @@ -156,6 +197,25 @@ where it was missing. Since it's not possible to know the expiry date and time of a cache item, the second optional argument of ``ChainAdapter`` is the default lifetime applied to those cache items (by default it's ``0``). +Traceable Adapter +~~~~~~~~~~~~~~~~~ + +This adapter wraps another adapter, and allows you to read a report of all of the +"calls" made to the adapter, including how long actions took, cache hits, misses +and more:: + + use Symfony\Component\Cache\Adapter\TraceableAdapter; + use Symfony\Component\Cache\Adapter\FilesystemAdapter; + + $fileCache = new FilesystemAdapter(); + + $cache = new TraceableAdapter(array($fileCache)); + + // work with the $cache adapter like normal + + // returns an array of TraceableAdapterEvent describing the calls + $events = $cache->getCalls(); + Proxy Cache Adapter ~~~~~~~~~~~~~~~~~~~ @@ -279,3 +339,4 @@ when all items are successfully deleted):: $cacheIsEmpty = $cache->clear(); .. _`Doctrine Cache`: https://github.com/doctrine/cache +.. _`Memcached`: http://php.net/manual/en/book.memcached.php From 96ed2dd6b50fc05e04fa156aeaa6fd938586f9d9 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 27 Jan 2017 17:27:58 -0500 Subject: [PATCH 2/8] Adding docs about converting between PSR6 and PSR16 --- components/cache.rst | 5 ++ components/cache/psr6_psr16_adapters.rst | 86 ++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 components/cache/psr6_psr16_adapters.rst diff --git a/components/cache.rst b/components/cache.rst index b1b8da1f69d..439020c4262 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -39,6 +39,11 @@ This component includes *two* different approaches to caching: Both methods support the *same* cache adapters and will give you very similar performance. +.. tip:: + + The component also contains adapters to convert between PSR-6 and PSR-16 caches. + See :doc:`/components/cache/psr_psr16_adapters`. + .. _cache-component-psr6-caching: More Advanced Caching (PSR-6) diff --git a/components/cache/psr6_psr16_adapters.rst b/components/cache/psr6_psr16_adapters.rst new file mode 100644 index 00000000000..3d64739b67f --- /dev/null +++ b/components/cache/psr6_psr16_adapters.rst @@ -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 <>` +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 +-------------------------------------------- + +Suppose you want to work with a class that requires a PSR-16 Cache pool object. For +example:: + + use Psr\Cache\CacheItemPoolInterface; + + // just a made-up class for the example + class GitHubApiClient + { + // ... + + // this requires a PSR-16 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 +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(); + + // a PSR-16 cache that uses your cache internally! + $psr16Cache = new SimpleCacheAdapter($psr6Cache); + + // now use this wherever you want + $githubApiClient = new GitHubApiClient($psr16Cache); + +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 object. For +example:: + + use Psr\SimpleCache\CacheInterface; + + // just a made-up class for the example + class GitHubApiClient + { + // ... + + // this requires a PSR-6 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 +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(); + + // a PSR-6 cache that uses your cache internally! + $psr6Cache = new Psr6Cache($psr16Cache); + + // now use this wherever you want + $githubApiClient = new GitHubApiClient($psr6Cache); From aa2354df734ae60d6949e2ce85f6b03c9176f774 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 27 Jan 2017 17:34:59 -0500 Subject: [PATCH 3/8] Fixing based on feedback! --- components/cache.rst | 142 +++++++++++++++---------------- components/cache/cache_pools.rst | 12 +-- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/components/cache.rst b/components/cache.rst index 439020c4262..a76ebfdc6fc 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -44,69 +44,6 @@ Both methods support the *same* cache adapters and will give you very similar pe The component also contains adapters to convert between PSR-6 and PSR-16 caches. See :doc:`/components/cache/psr_psr16_adapters`. -.. _cache-component-psr6-caching: - -More Advanced Caching (PSR-6) ------------------------------ - -To use the more-advanced, PSR-6 Caching abilities, you'll need to learn its key -concepts: - -**Item** - A single unit of information stored as a key/value pair, where the key is - the unique identifier of the information and the value is its contents; -**Pool** - A logical repository of cache items. All cache operations (saving items, - looking for items, etc.) are performed through the pool. Applications can - define as many pools as needed. -**Adapter** - It implements the actual caching mechanism to store the information in the - filesystem, in a database, etc. The component provides several ready to use - adapters for common caching backends (Redis, APCu, etc.) - -Basic Usage (PSR-6) -------------------- - -This part of the component is an implementation of `PSR-6`_, which means that its -basic API is the same as defined in the standard. Before starting to cache information, -create the cache pool using any of the built-in adapters. For example, to create -a filesystem-based cache, instantiate :class:`Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter`:: - - use Symfony\Component\Cache\Adapter\FilesystemAdapter; - - $cache = new FilesystemAdapter(); - -Now you can create, retrieve, update and delete items using this cache pool:: - - // create a new item by trying to get it from the cache - $numProducts = $cache->getItem('stats.num_products'); - - // assign a value to the item and save it - $numProducts->set(4711); - $cache->save($numProducts); - - // retrieve the cache item - $numProducts = $cache->getItem('stats.num_products'); - if (!$numProducts->isHit()) { - // ... item does not exists in the cache - } - // retrieve the value stored by the item - $total = $numProducts->get(); - - // remove the cache item - $cache->deleteItem('stats.num_products'); - -For a list of all of the supported adapters, see :doc:`/components/cache/cache_pools`. - -Advanced Usage (PSR-6) ----------------------- - -.. toctree:: - :glob: - :maxdepth: 1 - - cache/* - .. _cache-component-psr16-caching: Simple Caching (PSR-16) @@ -114,7 +51,7 @@ Simple Caching (PSR-16) This part of the component is an implementation of `PSR-16`_, which means that its basic API is the same as defined in the standard. First, create a cache object from -one of the built-in cache clases. For example, to create a filesystem-based cache, +one of the built-in cache classes. For example, to create a filesystem-based cache, instantiate :class:`Symfony\\Component\\Cache\\Simple\\FilesystemCache`:: use Symfony\Component\Cache\Simple\FilesystemCache; @@ -148,20 +85,20 @@ Now you can create, retrieve, update and delete items using this object:: You can also work with multiple items at once:: - $cache->setMultiple([ + $cache->setMultiple(array( 'stats.num_products' => 4711, 'stats.num_users' => 1356, - ]); + )); - $stats = $cache->getMultiple([ + $stats = $cache->getMultiple(array( 'stats.num_products', 'stats.num_users', - ]); + )); - $cache->deleteMultiple([ + $cache->deleteMultiple(array( 'stats.num_products', 'stats.num_users', - ]); + )); Available Simple Cache (PSR-16) Classes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -170,7 +107,7 @@ The following cache adapters are available: .. tip:: - To find out more about each of these classes, you can read th + To find out more about each of these classes, you can read the :doc:`PSR-6 Cache Pool ` page. These "Simple" (PSR-16) cache classes aren't identical to the PSR-6 Adapters on that page, but each share constructor arguments and use-cases. @@ -188,6 +125,69 @@ The following cache adapters are available: * :class:`Symfony\\Component\\Cache\\Simple\\RedisCache` * :class:`Symfony\\Component\\Cache\\Simple\\TraceableCache` +.. _cache-component-psr6-caching: + +More Advanced Caching (PSR-6) +----------------------------- + +To use the more-advanced, PSR-6 Caching abilities, you'll need to learn its key +concepts: + +**Item** + A single unit of information stored as a key/value pair, where the key is + the unique identifier of the information and the value is its contents; +**Pool** + A logical repository of cache items. All cache operations (saving items, + looking for items, etc.) are performed through the pool. Applications can + define as many pools as needed. +**Adapter** + It implements the actual caching mechanism to store the information in the + filesystem, in a database, etc. The component provides several ready to use + adapters for common caching backends (Redis, APCu, etc.) + +Basic Usage (PSR-6) +------------------- + +This part of the component is an implementation of `PSR-6`_, which means that its +basic API is the same as defined in the standard. Before starting to cache information, +create the cache pool using any of the built-in adapters. For example, to create +a filesystem-based cache, instantiate :class:`Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter`:: + + use Symfony\Component\Cache\Adapter\FilesystemAdapter; + + $cache = new FilesystemAdapter(); + +Now you can create, retrieve, update and delete items using this cache pool:: + + // create a new item by trying to get it from the cache + $numProducts = $cache->getItem('stats.num_products'); + + // assign a value to the item and save it + $numProducts->set(4711); + $cache->save($numProducts); + + // retrieve the cache item + $numProducts = $cache->getItem('stats.num_products'); + if (!$numProducts->isHit()) { + // ... item does not exists in the cache + } + // retrieve the value stored by the item + $total = $numProducts->get(); + + // remove the cache item + $cache->deleteItem('stats.num_products'); + +For a list of all of the supported adapters, see :doc:`/components/cache/cache_pools`. + +Advanced Usage (PSR-6) +---------------------- + +.. toctree:: + :glob: + :maxdepth: 1 + + cache/* + .. _`PSR-6`: http://www.php-fig.org/psr/psr-6/ .. _`PSR-16`: http://www.php-fig.org/psr/psr-16/ .. _Packagist: https://packagist.org/packages/symfony/cache diff --git a/components/cache/cache_pools.rst b/components/cache/cache_pools.rst index c9d51154355..ba95117d0cb 100644 --- a/components/cache/cache_pools.rst +++ b/components/cache/cache_pools.rst @@ -5,8 +5,8 @@ single: Redis Cache single: PDO Cache, Doctrine DBAL Cache -Cache Pools & Supported Adapters -================================ +Cache Pools and Supported Adapters +================================== Cache Pools are the logical repositories of cache items. They perform all the common operations on items, such as saving them or looking for them. Cache pools @@ -140,12 +140,12 @@ helper allows creating a connection to a pool of Memcached server using a DSN co 'memcached://user:pass@localhost?weight=33', // options, including username, password and Memcached::OPT_* options - ['persistent_id' => '_products_cache'] + array('persistent_id' => '_products_cache') ); - $memcachedClient = MemcachedAdapter::createConnection([ + $memcachedClient = MemcachedAdapter::createConnection(array( array('192.168.1.100', 11211, 33), array('192.168.1.101', 11211, 33) - ]); + )); $cache = new MemcachedAdapter($memcachedClient); @@ -209,7 +209,7 @@ and more:: $fileCache = new FilesystemAdapter(); - $cache = new TraceableAdapter(array($fileCache)); + $cache = new TraceableAdapter($fileCache); // work with the $cache adapter like normal From 9887c98421675ee847fd58f025513e3ad302cbbd Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 27 Jan 2017 17:39:27 -0500 Subject: [PATCH 4/8] Reversing my 6-16 - got myself totally confused :) --- components/cache/psr6_psr16_adapters.rst | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/components/cache/psr6_psr16_adapters.rst b/components/cache/psr6_psr16_adapters.rst index 3d64739b67f..f7f93fdb9b9 100644 --- a/components/cache/psr6_psr16_adapters.rst +++ b/components/cache/psr6_psr16_adapters.rst @@ -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; @@ -24,14 +24,14 @@ 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:: @@ -39,19 +39,19 @@ 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; @@ -61,14 +61,14 @@ 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:: @@ -76,11 +76,11 @@ 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); From 7af448be5bf5ef980de57833c3c977ff830bd4dc Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 2 Feb 2017 14:01:59 -0500 Subject: [PATCH 5/8] Tweaks after feedback! --- components/cache.rst | 2 +- components/cache/cache_pools.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/cache.rst b/components/cache.rst index a76ebfdc6fc..058b59b0a4c 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -78,7 +78,7 @@ Now you can create, retrieve, update and delete items using this object:: // $numProducts = $cache->get('stats.num_products', 100); // remove the cache key - $cache->deleteItem('stats.num_products'); + $cache->delete('stats.num_products'); // clear *all* cache keys $cache->clear(); diff --git a/components/cache/cache_pools.rst b/components/cache/cache_pools.rst index ba95117d0cb..c0aaf82b393 100644 --- a/components/cache/cache_pools.rst +++ b/components/cache/cache_pools.rst @@ -142,6 +142,8 @@ helper allows creating a connection to a pool of Memcached server using a DSN co // options, including username, password and Memcached::OPT_* options array('persistent_id' => '_products_cache') ); + + // alternate syntax: array notations for the servers $memcachedClient = MemcachedAdapter::createConnection(array( array('192.168.1.100', 11211, 33), array('192.168.1.101', 11211, 33) From 14dba61968f0e6aa4019393be9bb1c8b27f28dd3 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 2 Feb 2017 14:03:30 -0500 Subject: [PATCH 6/8] Finishing my todo --- components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cache.rst b/components/cache.rst index 058b59b0a4c..4afa72be4cb 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -32,7 +32,7 @@ This component includes *two* different approaches to caching: :ref:`PSR-6 Caching `: A fully-featured cache system, which includes cache "pools", more advanced - cache "items", and :ref:`cache tagging for invalidation `. + cache "items", and :ref:`cache tagging for invalidation `. :ref:`PSR-16 Simple Caching `: A simple way to store, fetch and remove items from a cache. From e81c887a9fdc664256dc7d8129ddbdb8a53fee81 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 2 Feb 2017 15:15:26 -0500 Subject: [PATCH 7/8] Fixing another bad link --- components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cache.rst b/components/cache.rst index 4afa72be4cb..2bb5e60bd8b 100644 --- a/components/cache.rst +++ b/components/cache.rst @@ -42,7 +42,7 @@ Both methods support the *same* cache adapters and will give you very similar pe .. tip:: The component also contains adapters to convert between PSR-6 and PSR-16 caches. - See :doc:`/components/cache/psr_psr16_adapters`. + See :doc:`/components/cache/psr6_psr16_adapters`. .. _cache-component-psr16-caching: From d9b9a047cafb23d31d1331e7e11acc9b54e1969b Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 3 Feb 2017 17:19:44 -0500 Subject: [PATCH 8/8] Adding more missing links --- components/cache/psr6_psr16_adapters.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/cache/psr6_psr16_adapters.rst b/components/cache/psr6_psr16_adapters.rst index f7f93fdb9b9..4d818449618 100644 --- a/components/cache/psr6_psr16_adapters.rst +++ b/components/cache/psr6_psr16_adapters.rst @@ -6,8 +6,8 @@ Adapters For Interoperability between PSR-6 and PSR-16 Cache ============================================================ -Sometimes, you may have a Cache object that implements the :ref:`PSR-16 <>` -standard, but need to pass it to an object that expects a :ref:`PSR-6 <>` +Sometimes, you may have a Cache object that implements the :ref:`PSR-16 ` +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.