Re: New Cache Class
| From: | Christian Stocker | Date: | Sun, 24 Aug 2003 15:59:09 +0000 |
| Subject: | Re: New Cache Class | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20457@lists.php.net to get a copy of this message | ||
Hi
There are already 2 different Cache "Classes" in PEAR.
Therefore the usual questions:
What makes your approach so differnt to be included in PEAR in contrast to the others?
What's the difference to the existing ones?
Can't you merge your effort with one of the others?
chregu
On 8/24/03 5:47 PM, David Rech wrote:
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-- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid 0x5CE1DECB