Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
23 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
Prev Previous commit
Next Next commit
Used a better example
  • Loading branch information
javiereguiluz committed Apr 25, 2016
commit 21da04eb4a9ecbfb199676c23bad38b6d19e5e7c
16 changes: 8 additions & 8 deletions components/cache/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ and define the namespace used to store the items as the first argument::
Now you can create, retrieve, updated and delete items using this cache pool::

// create a new item by trying to get it from the cache
$item = $cache->getItem('user_id');
$numProducts = $cache->getItem('stats.num_products');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable naming is confusing... What about $numProductsCacheItem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I refactored this example before and forgot to update that part. It's updated now. Thanks.


// assign a value to the item and save it
$item->set('4711');
$cache->save($item);
$numProducts->set('4711');
$cache->save($numProducts);

// retrieve the cached item
$cachedUser = $cache->getItem('user_id');
// retrieve the cache item
$cachedNumProducts = $cache->getItem('stats.num_products');
// check whether the item exists in the cache
$isCached = $cachedUser->isHit();
$isCached = $cachedNumProducts->isHit();
// retrieve the value stored by the item
$userId = $cachedUser->get();
$numProducts = $cachedNumProducts->get();

// remove the cache item
$cache->deleteItem('user_id');
$cache->deleteItem('stats.num_products');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add links to the other sections in a new section at the end of the introduction

.. _`PSR-6`: http://www.php-fig.org/psr/psr-6/