PHP caching

I improved my caching library to not only support the caching of data or web page, it now supports the caching of .php include files. So instead of including several php files you can configure the library to cache all your code in one single cached include file.

I will release the code within one week on Woxxom

Please remember that this is not a big bloated cache library, it’s under 100 lines of code and can be used for anything.

Sample

if ( !$output=CacheIncludesFetch(‘core-headers’,60,2) )
{ $files=array();
$files[]=siteBasePath.’core/authentication.php’;
$files[]=siteBasePath.’core/links.php’;
$files[]=siteBasePath.’core/events.php’;
$files[]=siteBasePath.’core/posts.php’;
$files[]=siteBasePath.’core/misc.php’;
$files[]=siteBasePath.’core/mail.php’;
CacheIncludesSaveTo(‘core-headers’,$files);
}

here we have the function CacheIncludesFetch which will try to load the ‘core-headers’ file from the cache, if it exists, the file will be included. If not, we define an array with all the filenames that you want to include. The CacheIncludesSaveTo function will create a single ‘core-headers’ file containing all the code found in your includes

that’s it, you now have optimized your code! 🙂  PHP is very slow when it comes to include a file (ie: include, include-once, require, require-once) .

the value ’60’ next to the cache name is the time at which the cached data will expires.

simple enough!

Advertisements

~ by lucraymond on November 30, 2006.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: