Expanded on object caching.

This commit is contained in:
Steven Benner
2012-07-12 18:25:28 -07:00
parent 721889ad08
commit 5ba8978d46

View File

@@ -4,17 +4,21 @@ isChild: true
## Object Caching ## Object Caching
There are times when it is advantageous to cache individual objects in your code, such as with data that is expensive to There are times when it can be advantageous to cache individual objects in your code, such as with data that is
get or database calls where the result is unlikely to change. You can use object caching software to hold pieces of data expensive to get or database calls where the result is unlikely to change. You can use object caching software to hold
in memory for extremely fast access later on. If you save these items in a data store after you get them then access the these pieces of data in memory for extremely fast access later on. If you save these items to a data store after you
data for following requests from cache you will see significant performance increases and reduced load on your database retrieve them, then pull them directly from the cache for following requests you can gain a significant improvement in
servers. performance as well as reduce load on your database servers.
The most common memory object caching systems are APC and memcached. APC is a great choice for caching, it comes with The most commonly used memory object caching systems are APC and memcached. APC is a great choice for object caching as
PHP and is very easy to setup and to use, but it is tied to the server it is installed on. Memcached on the other hand well as opcode caching *(see above)*. APC comes bundled with PHP and it is very easy to setup and to use, the only
is installed as a separate service and can be accessed across the network, meaning that you can store values in a possible downside is that it is tied to the server it is installed on. Memcached on the other hand is installed as a
hyper-fast data store in a central location and many different systems can pull from it. In a networked configuration separate service and can be accessed across the network, meaning that you can store objects in a hyper-fast data store
APC will outperform memcached in terms of access speed, but memcached will be able to scale up faster and further. in a central location and many different systems can pull from it.
In a networked configuration APC will usally outperform memcached in terms of access speed, but memcached will be able
to scale up faster and further. If you do not expect to have multiple servers running your application, or do not need
the extra features that memcached offers then APC is probably your best choice for object caching.
Example logic using APC: Example logic using APC:
@@ -30,8 +34,8 @@ if (!$data)
Learn more about popular object caching systems. Learn more about popular object caching systems.
* [APC](http://php.net/manual/en/book.apc.php) * [APC](http://php.net/manual/en/book.apc.php) (Can do opcode caching and object caching)
* [APC Functions](http://php.net/manual/en/ref.apc.php) * [APC Functions](http://php.net/manual/en/ref.apc.php)
* [Memcached](http://memcached.org/) * [Memcached](http://memcached.org/)
* [Redis](http://redis.io/) * [Redis](http://redis.io/)
* [WinCache](http://php.net/manual/en/book.wincache.php) (Windows Only) * [WinCache](http://php.net/manual/en/book.wincache.php) (Windows Only, can do opcode caching and object caching)