I've got a website that essentially only shows things with no forms and publish-will get. This site is PHP based and located on hosting that is shared. It rarely changes. I must enable caching with this website. Its hosting that is shared and so i require a solution that:

  • doesn't use Memcached
  • do not need to maneuver this site to VPS
  • dont use APC or any other things

So essentially what i must acomplish is cache every subsite to HTML and tell PHP to obtain for five minutes the HTML cached version of current subsite and display it to user. And after a few minutes to refresh the cache.

I have been searching for some during the internets and you will find some lessons and frameworks that support this type of kinky cache.

But things i need is simply one good library that's very simple to use.

I imagine results in by doing this:

<?

if (current_site_cache_is_valid())
{
   display_cached_version();
   die;
}

..mywebsite rendering code

?>

So simple because it sounds however i hope good quality fellow developer did library of the kind before. So are you aware such available, not so time intensive to implement solution?

You need to give skycache an attempt. edit : this project appears awesome too: cacheme

Another solution is by using .php/auto_prepend_file. Something similar to what's referred to within this tutorial: Output caching for beginners

This is the way I normally do that, however I'm not sure your URL design nor your directory / file layout.

I actually do this with .htaccess along with a [cde]­Docs.

The webserver inspections if your cached HTML file is available, and when yes, it's shipped. You may also check it's age.

Whether it's too old or maybe it doesn't is available your PHP script(s?) is began. At the outset of your script you start the output buffer­Docs. In the finish of the script, you get the output buffer and also you put the content in to the cache file and you output it.

The advantage of this option would be, that apache will deliver static files just in case they exist and there's you don't need to invoke a PHP process. Should you choose everything within PHP itself, you will not obtain that benefit.

I'd even go one step further and operate a cron-job that removes older cache-files rather than carrying out a time-check within the mod_rewrite. So now, you may make the rewrite less complex to should you prefer a .htaccess file rather than the .php.cached file.