New Cache Class

From: Date: Sun, 24 Aug 2003 15:47:31 +0000
Subject: New Cache Class
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-20456@lists.php.net to get a copy of this message
Hey List, First to say: Hello guys! Because I'm new at this list ;) I've made a tiny but well working cache class, I'll use it on my bulletin board which is under heavy development yet. The features are: - Able to assign dynamic content to cached content, So you only have to build the content which was changed since the last storing process - Store cached content to a defined path - build a "signature" for a requested page to identify it on the cache - add request parameters to exlude from the signature (like dynamic stuff e.g. session id's) - used output buffering to handle content What I'd like to add: - Cleaning mechanism to clean whole cache - Autocleaning after a max. Size of the cache directory is reached What It does NOT: - Decide whether you have to resave into cache or not, that is IMO a thing what the developer should do self carefully. Let me give an example for the usage... First we load the class and create a new instance: require_once DOCROOT."sources/lib/cache.php"; $cache = new cache($revBB->vars['use_cache'], array("ivb_session", "s")); So what we see is, $revBB->vars['use_cache'] is the config setting for cache usage in my board. The cache constructor expects true/false as the first parameter, and an optional array with GET keys to exclude. Now we check if the site is already on cache, if true we assign dynamic content to replace. if( $cache->getStatus() ) { //Assign dynamic "board info" $cache->assign("BOARD_INFO", $this->board_info()); //Get page and return return $cache->getPage(); } (The if statement is part of a class' method, that's why it returnes... :) That's it, now we've got the page from the cache, the dynamicly assigned content were replaced and we're happy. Now, the "save to cache" stuff: $cache->savePage($output); That's it, $output is the data to save...! I guess I should add saving from the output buffer by default if savePage() is called without params. Any comments? I'd like to PEARify the cache system, If you guys like it :-) Thanks, and nice startover into a new week, David Rech

« previous php.pear.dev (#20456) next »