A simple mode to cache php pages. Support automatic on sessions and querystrings.
To use this feature only add to the start of your code:
<?php
include "simple_cache_class.php";
$cache = new SimpleCachePhp(__FILE__);
?>
And this snippet at the end:
<?php $cache->CacheEnd(); ?>
For example, imagine that you have the following php page (uncached):
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>hello world</h1>
<p>Now is <?php echo date('d/m/Y h:i:s'); ?></p>
</body>
</html>
Cached:
<?php
include "simple_cache_class.php";
$cache = new SimpleCachePhp(__FILE__);
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>hello world</h1>
<p>Now is <?php echo date('d/m/Y h:i:s'); ?></p>
</body>
</html>
<?php $cache->CacheEnd(); ?>
The first time the page is accessed it is generated normally. With ob_start, ob_get_contents and fopen a file is created with the cache.
The files are stored in the /cache. At each new access is checked if cache exists and has not expired.
The cache takes into account the filename, sessions and querystrings.
In the example above, the file would be generated: /cache/index.php__, and expire in 24 hours.
$cache = new SimpleCachePhp($filename, $time, $ignoreKeysOnParametrize, $folderCache);
$filename
The name of the cache file will be saved. To use the current name of the file, use: __FILE__
$time
The time the cache is stored before expiring. Default: 86400 (24 hours)
$ignoreKeysOnParametrize
An array of keys that should be ignored. For example, if you use a login session but the pages are identical. Default: null
$folderCache
The folder that the files are stored. /cache/