tags:

views:

50

answers:

2

I am about to begin building a small application for a user to manage the content of a simple website. Since the content will be changing relatively infrequently, it struck me that it would be a waste to dynamically generate each page upon request--all of the content on the site will remain the same between edits. The simple solution I came up with is to build the application so that when edits are submitted a new page is generated and saved. However, this seems like a poor reimplementation of caching. Is writing a script to save static pages the "wrong" way to go about this? Is it fine for small sites? Are there any light weight tools worth using to implement the caching of entire pages for a small project such as this one?

Keep in mind that I am using a shared hosting solution and do not have the ability to tweak / install things.

+1  A: 

The advantage of generating a static site versus using caching is that there's never any need to check if the page is in the cache or has been removed due to LRU algorithms. As long as you generate them promptly when an edit is made I see no problems with how you're doing it.

Ignacio Vazquez-Abrams
Thanks for the answer. It gives me a lot of confidence, as I can from your rep and profile that you are quite knowledgeable.
Oren
A: 

When I ran in those kind of projects, small projects, I simply made a small tool to cache all accessed pages from that site.

for example:

if someone is opening my rewrite: http://www.example.com/about-us.html it would access http://www.example.com/about-us.php

in my global file I made something like this:

when someone enters that page I check if /cache/about-us.html exists, if it didn't I would $cache_content = implode('', file('http://www.example.com/about-us.php')); to open webpage from outside, and write to disk .. I also added some expire headers like:

<?php
$cache_content = implode('', file('http://www.example.com/about-us.php'));
$date_cached = date('U');

$data = $date_cached."\n".$cache_content;

$fp = fopen('/cache/about-us.html', 'w');
fwrite($fp, $data);
fclose($fp);
?>

then on global.php file like I told you above it checks for that file, if it finds it it opens and read that date, if date was 3 days old I regenerated the file.

I also added in CMS a way to purge all cache.

Best of luck.

Mihai Iorga
Doing `file_get_contents()` would be way faster than `implode('', file())`. Also `file_put_contents()` easily replaces the `fopen()`, `fwrite()` and `fclose()` calls.
Alix Axel
this is because I'm doing PHP scripting for about 10 years now. And I kind of newbie in new functions. Yet, you're right. Thank you for pointing.
Mihai Iorga