Update _posts/10-03-01-Object-Caching.md

Adjusted caching example-pattern, so it will not trigger 2 cache-lookups
This commit is contained in:
Markus Staab
2013-01-06 16:06:26 +01:00
parent 3a79e14a36
commit c7774d7f23

View File

@@ -32,12 +32,13 @@ Example logic using APC:
{% highlight php %}
<?php
// check if there is data saved as 'expensive_data' in cache
if (apc_fetch('expensive_data') === false) {
// data is not in cache; save expensive call for later use
apc_add('expensive_data', get_expensive_data());
$data = apc_fetch('expensive_data');
if ($data === false) {
// data is not in cache; save result of expensive call for later use
apc_add('expensive_data', $data = get_expensive_data());
}
print_r(apc_fetch('expensive_data'));
print_r($data);
{% endhighlight %}
Learn more about popular object caching systems: