-
- Notifications
You must be signed in to change notification settings - Fork 5.3k
Added the documentation for the Cache component #6515
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
Changes from 1 commit
7582785
21da04e
05b7ba9
401410d
6acd591
b1c5b12
c6917bd
fc84df8
599ed0a
687910d
2d71222
6d21b01
e1bce89
81ec988
c44b7c2
11549e2
930a2d1
94011a7
cf07d4a
f2234ed
1628349
657659f
50f0d58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -34,15 +34,15 @@ Cache items are created with the ``getItem($key)`` method of the cache pool. The | |
argument is the key of the item:: | ||
| ||
// $cache pool object was created before | ||
$cachedNumProducts = $cache->getItem('stats.num_products'); | ||
$numProducts = $cache->getItem('stats.num_products'); | ||
| ||
Then, use the ``set($value)`` method to set the data stored in the cache item:: | ||
| ||
// storing a simple integer | ||
$cachedNumProducts->set(4711); | ||
$numProducts->set(4711); | ||
| ||
// storing an array | ||
$cachedNumProducts->set(array( | ||
$numProducts->set(array( | ||
'category1' => 4711, | ||
'category2' => 2387, | ||
)); | ||
| @@ -56,7 +56,7 @@ Then, use the ``set($value)`` method to set the data stored in the cache item:: | |
The key and the value of any given cache item can be obtained with the | ||
corresponding *getter* methods:: | ||
| ||
$cacheItem = $cache->getItem('logged_users'); | ||
$cacheItem = $cache->getItem('exchange_rate'); | ||
// ... | ||
$key = $cacheItem->getKey(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a difference between | ||
$value = $cacheItem->get(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -53,18 +53,18 @@ a filesystem-based cache, instantiate :class:`Symfony\\Component\\Cache\\Adapter | |
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 | ||
$cachedNumProducts = $cache->getItem('stats.num_products'); | ||
$numProducts = $cache->getItem('stats.num_products'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable naming is confusing... What about There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
$cachedNumProducts->set(4711); | ||
$cache->save($cachedNumProducts); | ||
$numProducts->set(4711); | ||
$cache->save($numProducts); | ||
| ||
// retrieve the cache item | ||
$cachedNumProducts = $cache->getItem('stats.num_products'); | ||
$numProducts = $cache->getItem('stats.num_products'); | ||
// check whether the item exists in the cache | ||
$isCached = $cachedNumProducts->isHit(); | ||
$isCached = $numProducts->isHit(); | ||
| ||
// retrieve the value stored by the item | ||
$numProducts = $cachedNumProducts->get(); | ||
$total = $numProducts->get(); | ||
| ||
// remove the cache item | ||
$cache->deleteItem('stats.num_products'); | ||
|
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.
let's use an API link here