Nen Cache - File cache class

Started on the old forum in June 2011 · view the original in the archive · old links redirect here

#cache #class #file #nen

5 replies · 1,068 views · started 15 years ago · 1 min read

5 participants
morency Senior · 488 posts #1

This class can be used to cache the output of PHP generated pages in files.

It can capture the output of a PHP script section and cache it by storing the output in files.

The output data is cached for a given timeout period. While the cache does not expire, the data is retrieved from the cache file.

The cache file path and the timeout period are configurable.

Usage : view example.php

Simple usage :

<?php
include "nen.class.php";

$path = 'cache/'; // We set cache path ! Do not forget '/'
$cache_adv = new nencache;
$cache_name='page1'; // 
$cache_time = '3600'; // (3600s = 1h :D )
if ($cache_adv -> start ($cache_name,$cache_time,$path)) {

///my normal page content here 
$cache_adv -> build ($path);
}
?>

I use this class to cache results from mysql query . DO not include dinamic ads (e.g. from admob) in this code , because will be cached ..and is not good 🙂

An way to add dinamic ads in cached files can be the usage of some text e.g. [top_admob_ad] and on output replace this with admob function :-?

If you have a better (or not) cache class , please post here .

Unamos los corazones,hoy todos somos multicolores!

Attachments: NEN.cache.zip
morency Senior · 488 posts #3
///content here will not be cached

if ($cache_adv -> start ($cache_name,$cache_time,$path)) {

///my normal page content here
/// all content from here will be cached 
$cache_adv -> build ($path);
}

///content here will not be cached

Unamos los corazones,hoy todos somos multicolores!

kafa Junior · 12 posts #4

Nice code 🙂 I hope i can implement it into my forum, but one hour seems to be to much for a dynamic site, 5 mins would be a better choice 🙂

http://merak.mobi - Love at first click

i0nutzxp Developer · 150 posts #5

Just delete the cache file when you add something new.

<?php unlink('World/Europe/Romania.country'); ?>
Anshul Senior · 296 posts #6

u cn use memcache also 🙂

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close