From bde25d971bfbf4a54f1d40eedfd3290ebb5f91e5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 21 Dec 2010 09:31:21 -0600 Subject: Initial commit of Caching Driver. --- user_guide/libraries/caching.html | 193 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 user_guide/libraries/caching.html (limited to 'user_guide/libraries') diff --git a/user_guide/libraries/caching.html b/user_guide/libraries/caching.html new file mode 100644 index 000000000..e4651dc4a --- /dev/null +++ b/user_guide/libraries/caching.html @@ -0,0 +1,193 @@ + + + + + +Caching Driver : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ +

Caching Driver

+ +

CodeIgniter features wrappers around some of the most popular forms of fast and dynamic caching. All but file-based caching require specific server requirements, and a Fatal Exception will be thrown if server requirements are not met.

+ +

Table of Contents

+ + +

Available Drivers

+ + +

Example Usage

+ +

The following example will load the cache driver, specify APC as the driver to use, and fall back to file-based caching if APC is not available in the hosting environment.

+ + +$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
+
+if ( ! $foo = $this->cache->get('foo'))
+{
+     echo 'Saving to the cache!<br />';
+     $foo = 'foobarbaz!';
+
+     // Save into the cache for 5 minutes
+     $this->cache->save('foo', $foo, 300);
+}
+
+echo $foo; +
+ +

Function Reference

+ +

is_supported(driver['string'])

+ +

This function is automatically called when accessing drivers via $this->cache->get(). However, if the individual drivers are used, make sure to call this function to ensure the driver is supported in the hosting environment.

+ + +if ($this->cache->apc->is_supported())
+{
+     if ($data = $this->cache->apc->get('my_cache'))
+     {
+          // do things.
+     }
+} +
+ +

get(id['string'])

+ +

This function will attempt to fetch an item from the cache store. If the item does not exist, the function will return FALSE.

+$foo = $this->cache->get('my_cached_item'); + +

save(id['string'], data['mixed'], ttl['int'])

+ +

This function will save an item to the cache store. If saving fails, the function will return FALSE.

+

The optional third parameter (Time To Live) defaults to 60 seconds.

+$this->cache->save('cache_item_id', 'data_to_cache'); + +

delete(id['string'])

+ +

This function will delete a specific item from the cache store. If item deletion fails, the function will return FALSE.

+$this->cache->delete('cache_item_id'); + +

clean()

+ +

This function will 'clean' the entire cache. If the deletion of the cache files fails, the function will return FALSE.

+ +$this->cache->clean(); + +

cache_info()

+ +

This function will return information on the entire cache.

+ +var_dump($this->cache->cache_info()); + +

get_metadata(id['string'])

+ +

This function will return detailed information on a specific item in the cache.

+ +var_dump($this->cache->get_metadata('my_cached_item')); + +

Drivers

+ +

Alternative PHP Cache (APC) Caching

+ +

All of the functions listed above can be accessed without passing a specific adapter to the driver loader as follows:

+$this->load->driver('cache');
+ $this->cache->apc->save('foo', 'bar', 10);
+

For more information on APC, please see http://php.net/apc

+ +

File-based Caching

+ +

Unlike caching from the Output Class, the driver file-based caching allows for pieces of view files to be cached. Use this with care, and make sure to benchmark your application, as a point can come where disk I/O will negate positive gains by caching.

+ +

All of the functions listed above can be accessed without passing a specific adapter to the driver loader as follows:

+$this->load->driver('cache');
+ $this->cache->file->save('foo', 'bar', 10);
+ +

Memcached Caching

+ +

Multiple Memcached servers can be specified in the memcached.php configuration file, located in the application/config/ directory. + +

All of the functions listed above can be accessed without passing a specific adapter to the driver loader as follows:

+$this->load->driver('cache');
+ $this->cache->memcached->save('foo', 'bar', 10);
+ +

For more information on Memcached, please see http://php.net/memcached

+ +

Dummy Cache

+ +

This is a caching backend that will always 'miss.' It stores no data, but lets you keep your caching code in place in environments that don't support your chosen cache.

+ +
+ + + + + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b