This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/includes/kohana/modules/cache/guide/cache/index.md
2011-07-18 16:20:23 +10:00

4.0 KiB

About Kohana Cache

[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.

Supported cache engines

  • APC ([Cache_Apc])
  • eAccelerator ([Cache_Eaccelerator])
  • File ([Cache_File])
  • Memcached ([Cache_Memcache])
  • Memcached-tags ([Cache_Memcachetag])
  • SQLite ([Cache_Sqlite])
  • Xcache ([Cache_Xcache])

Introduction to caching

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.

What the Kohana Cache module does (and does not do)

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.

Choosing a cache provider

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:

  1. Does the cache need to be distributed? This is an important consideration as it will severely limit the options available to solutions such as Memcache when a distributed solution is required.
  2. Does the cache need to be fast? In almost all cases retrieving data from a cache is faster than execution. However generally memory based caching is considerably faster than disk based caching (see table below).
  3. How much cache is required? Cache is not endless, and memory based caches are subject to a considerably more limited storage resource.
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.

Minimum requirements

  • Kohana 3.0.4
  • PHP 5.2.4 or greater