You are on page 1of 2

http://laravel.com/docs/4.

2/cache
store cache 5s,
sau 5s thi coi nhu cache ko exist --> load lai
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));
apc_exists
First, it's important to know that if one tries to store a key which already exi
sts with a specific TTL, AND the ttl hasn't passed yet, a new entry will be crea
ted; it doesn't matter if the key is the same, internally there will be two entr
ies of the same key.
Second, APC can fail (miss). Even when there's no apparent reason for it. Why? A
PC was apparently created favoring speed over consistency, meaning that when the
APC driver is busy doing some cleanout, it will simply return NULL instead of w
aiting until it's done, even though the data exists. The long version of this is
here: http://phpadvent.org/2010/share-and-enjoy-by-gopal-vijayaraghavan
An exists check using apc_fetch could look like:
public function has($key) {
apc_fetch($key, $exists);
return $exists;
}
Firstly like many people has rightly pointed out.
APC is not persistent.
It was for me hard to accept this statement without a practical explanation or e
ven better a guide on how to work with it.
I've come to find that there are some rules or rather pitfalls to be aware of many still eludes me. Using the APC API means using apc_fetch and apc_store both
of these can fail, or as it is more correctly put, miss. And why you sometimes
receive NULL when you expected data is where the mystery lies.
Here are some random bits of information:
If you try to store a value before the TTL runs out a new entry will be created.
So slow down writing or decrease TTL.
Play around with apc.ttl and apc.user_ttl till you find something that suits you
- until you see lots of hits and not to many entries.
apc_fetch and apc_store can return NULL for a number of reasons, some hinted abo
ve, such as ttl another reason can be a key fetch timeout. But the point is desi
gn-around it. Expect this.
As far as I know it's still not possible to use shared memory cache with any PHP
cacher amongst multiple processes... anyway, unless you're under extremely heav
y load you should be fine with separate caches, I suppose, since they'll be fill
ed pretty quickly. And hey, RAM is cheap nowadays!
Now, all is fine, APC helps a lot with speed improvements. I know it's best to u

se centralized caching (like memcached) when running multiple nodes, but for now
, we do not have a spare node available yet.
https://groups.drupal.org/node/272983
BOOK: Professional Website Performance: Optimizing the Front-End and Back-End
http://jondavidjohn.com/simple-wordpress-caching-using-apc-and-batcache/
http://doctrine-orm.readthedocs.org/en/latest/reference/caching.html

You might also like