Part of the EllisLab Network
   
1 of 3
1
Khaos :: KhCache
Posted: 25 January 2008 09:25 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  01-24-2008

Updated - 26/03/2008 - Download - Khaos::KhCache-0.3

Introduction
KhCache is a pretty basic caching library currently with two containers (File and APC), the library is designed to complement codeigniters own caching system by allowing you to cache the output of smaller segments of code when no full page cache is available for CI to directly display.

Quick Reference

/*
 * KhCache
 *
 * mixed  fetch ( string $key)
 * bool   store ( string $key, mixed $data [, int $ttl] )
 * mixed  call ( callback $func [, array $args [, int $ttl ]] )
 * bool   delete ( string $key )
 * bool   delete_all ( )
 * string generatekey ( mixed $arg1  [, mixed $arg2  [, mixed $...  ]] )
 * int    get_hits ( )
 * int    get_misses ( )
 */

// Example General Usage
if (($data $this->khcache->fetch('test')) === false)
{
    
/*
     * Resource intensive code here which places data to be
     * cached within the $data variable.
     */
            
    // Save Cache
    
$this->khcache->store('test'$data);
}

// Example Function Caching
$data $this->khcache->call('transform_xsl', array($xsl$xml)); 

Configuration
KhCache will work right out the box aslong as the system/cache folder is writable. However if you wish to change the behaviour of KhCache then create the config file khaos.php.

Below is a sample config which represents the default behaviour of KhCache.

$config['cache']  = array('container' => 'File',
                           
'ttl'       => 3600,
                           
'File'      => array('store'           => BASEPATH.'cache/',
                                                
'auto_clean'      => 10
                                                
'auto_clean_life' => 3600,                         
                                                
'auto_clean_all'  => false)); 

everything in the config file is optional so options only need to be specified if you wish to override the default behaviour. for example if you wished to use APC then the config would simply be

$config['cache'= array('container' => 'APC'); 

auto_clean - By default there is a 1 in 10 chance of the cache dir being cleaned, set to false to disable.
auto_clean_life - Files older than this will be removed.
auto_clean_all - By default only cache files prefixed with khcache_ are removed set to true to have khcache clean the entire directory

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ .(JavaScript must be enabled to view this email address) - IRC ] - Websites :: [ myWebWatch - KhaosLibrary ]

Profile
 
 
Posted: 25 January 2008 05:56 PM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3185
Joined  06-10-2007

Once again, really nice code Neophyte. Thanks wink

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

Profile
 
 
Posted: 01 February 2008 07:19 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  01-24-2008

ChangeLog - KhCache - 0.2

Feature - new method ‘call’ to make function caching easier
Feature - auto cleaning when using File container (based on the PEAR::Cache_Lite approach)

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ .(JavaScript must be enabled to view this email address) - IRC ] - Websites :: [ myWebWatch - KhaosLibrary ]

Profile
 
 
Posted: 01 February 2008 08:32 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  747
Joined  01-13-2008

Nice and simple. The Best way to code wink .

 Signature 

Yonti - I am Currently looking for a business partner, to create the best developer hosting out there. If your interested PM me.

Fluxity Lighting - My other company.


I’m a Proud Supporter and Sponser of Tomorrows Web.

Profile
 
 
Posted: 26 March 2008 06:43 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  01-24-2008

ChangeLog - KhCache - 0.3

Feature - new method ‘delete_all’ to clear all cache items

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ .(JavaScript must be enabled to view this email address) - IRC ] - Websites :: [ myWebWatch - KhaosLibrary ]

Profile
 
 
Posted: 02 April 2008 12:49 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  57
Joined  03-11-2008

This is pure gold. CI and EE should come with granular caching by default. I don’t understand how people run large sites without granular caching and expiration.

Your use of containers is great. Leaves room for other things like memcaching or even DB caching drivers.

Thank you for sharing.

Profile
 
 
Posted: 02 April 2008 01:22 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  709
Joined  06-07-2007

You have a typo in the comments, it’s “instantiate”, not “instanciate” raspberry

 Signature 

jtaby.com

Profile
 
 
Posted: 02 April 2008 04:32 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  01-24-2008

I’ll consider changing it in the next release, no promises though raspberry

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ .(JavaScript must be enabled to view this email address) - IRC ] - Websites :: [ myWebWatch - KhaosLibrary ]

Profile
 
 
Posted: 07 April 2008 07:09 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  7
Joined  06-06-2007

On one of my codeigniter sites I use different views based on the user IP address. I can only use db cache, on specific queries. Is there a good way to use KhCache?

Profile
 
 
Posted: 07 April 2008 12:52 PM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  593
Joined  02-04-2008

This looks very interesting, thanks for posting this Neophyte.

I understand this is a new project, but I would like to see a little more documentation.

Can this be called from a View? I think it would be nice to be able to cache your view as the final output but also be able to cache pieces of the view at different cache times to save on other processing.

Profile
 
 
Posted: 08 April 2008 02:38 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Avatar
Total Posts:  2
Joined  02-28-2007

Hi Neophyte!

This is very nice and useful code. CI’s page cache and db cache does not really cut it for me. (CI’s cache does not automatically invalidates caches - is my main concern)

 Signature 

You become what you think about.

Profile
 
 
   
1 of 3
1