Part of the EllisLab Network
   
1 of 3
1
Khaos :: KhCache
Posted: 25 January 2008 08:25 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  77
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 :: [ - IRC ]

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

Once again, really nice code Neophyte. Thanks wink

 Signature 

URI Language Identifier | Modular Extensions - PHP5 | Modular Separation - PHP5 | Widget plugin | Access Control library

Profile
 
 
Posted: 01 February 2008 06:19 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  77
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 :: [ - IRC ]

Profile
 
 
Posted: 01 February 2008 07:32 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  754
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 05:43 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  77
Joined  01-24-2008

ChangeLog - KhCache - 0.3

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

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ - IRC ]

Profile
 
 
Posted: 01 April 2008 11:49 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  55
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 12:22 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  06-07-2007

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

 Signature 

CodeExtinguisher
Download: codex2_rc14.2.zip - 219 KiloBytes of Gloriousness!
Demo: Public preview - login with preview:preview
Temporary Docs: PBWiki

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

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

 Signature 

Khaos :: [ ACL - Cache - Event ] - Contact :: [ - IRC ]

Profile
 
 
Posted: 07 April 2008 06:09 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  8
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 11:52 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  596
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 01:38 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Avatar
Total Posts:  3
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
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120453 Total Logged-in Users: 41
Total Topics: 126532 Total Anonymous Users: 3
Total Replies: 665340 Total Guests: 315
Total Posts: 791872    
Members ( View Memberlist )