Kohana_Cache provides a common interface to a variety of caching engines. Kohana_Cache_Tagging is supported where available natively to the cache system. Kohana Cache supports multiple instances of cache engines through a grouped singleton pattern.
Caching should be implemented with consideration. Generally, caching the result of resources is faster than reprocessing them. Choosing what, how and when to cache is vital. PHP APC is one of the fastest caching systems available, closely followed by Memcached. SQLite and File caching are two of the slowest cache methods, however usually faster than reprocessing a complex set of instructions.
Caching engines that use memory are considerably faster than file based alternatives. But memory is limited whereas disk space is plentiful. If caching large datasets, such as large database result sets, it is best to use file caching.
[!!] Cache drivers require the relevant PHP extensions to be installed. APC, eAccelerator, Memecached and Xcache all require non-standard PHP extensions.
This module provides a simple abstracted interface to a wide selection of popular PHP cache engines. The caching API provides the basic caching methods implemented across all solutions, memory, network or disk based. Basic key / value storing is supported by all drivers, with additional tagging and garbage collection support where implemented or required.
Kohana Cache does not provide HTTP style caching for clients (web browsers) and/or proxies (Varnish, Squid). There are other Kohana modules that provide this functionality.
Getting and setting values to cache is very simple when using the Kohana Cache interface. The hardest choice is choosing which cache engine to use. When choosing a caching engine, the following criteria must be considered:
Driver | Storage | Speed | Tags | Distributed | Automatic Garbage Collection | Notes |
---|---|---|---|---|---|---|
APC | Memory | Excellent | No | No | Yes | Widely available PHP opcode caching solution, improves php execution performance |
eAccelerator | Memory | Excellent | No | No | Yes | Limited support and no longer developed. Included for legacy systems |
File | Disk | Poor | No | No | No | Marginally faster than execution |
Memcache (tag) | Memory | Good | No (yes) | Yes | Yes | Generally fast distributed solution, but has a speed hit due to variable network latency |
Sqlite | Disk | Poor | Yes | No | No | Marginally faster than execution |
Xcache | Memory | Excellent | Yes | No | Yes | Very fast memory solution and alternative to APC |
It is possible to have hybrid cache solutions that use a combination of the engines above in different contexts. This is supported with Kohana Cache as well.