Kohana_Cache provides a common interface to a variety of caching engines. 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 |
Wincache | Memory | Excellent | No | No | Yes | Windows variant of APC |
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 and serialization |
Sqlite | Disk | Poor | Yes | No | No | Marginally faster than execution |
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