caching

Download Caching

If you can't read please download the document

Upload: clickemdianh

Post on 11-Dec-2015

1 views

Category:

Documents


0 download

DESCRIPTION

Caching

TRANSCRIPT

http://laravel.com/docs/4.2/cachestore cache 5s,sau 5s thi coi nhu cache ko exist --> load laiapc_store('foo', $bar);var_dump(apc_fetch('foo'));apc_existsFirst, it's important to know that if one tries to store a key which already exists with a specific TTL, AND the ttl hasn't passed yet, a new entry will be created; it doesn't matter if the key is the same, internally there will be two entries of the same key.Second, APC can fail (miss). Even when there's no apparent reason for it. Why? APC 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 waiting 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-vijayaraghavanAn 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 even 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 above, such as ttl another reason can be a key fetch timeout. But the point is design-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 heavy load you should be fine with separate caches, I suppose, since they'll be filled 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 use 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/272983BOOK: Professional Website Performance: Optimizing the Front-End and Back-Endhttp://jondavidjohn.com/simple-wordpress-caching-using-apc-and-batcache/http://doctrine-orm.readthedocs.org/en/latest/reference/caching.html