Search code examples
phpcachingfile-iocache-control

Caching a page to multiple files or a single file


I'm developing a wiki-like web app and each page has 5, individually-editable content parts to it.

I have a simple caching class that saves the rendered parts to a file.

If a part of the page has not changed, it loads the cache, if it has, it renders it and then saves it to cache.

Because the page has 5 parts that are separately editable, I am saving each part as its own file, so when an edit is made, only that part is re-rendered and cached.

But, this also mean that every load, 5 files are read and included in the code.

Is it better to do it this way, or save the entire page in a single cache file?


Solution

  • That depends on multiple factors, I guess...

    • site load
    • file sizes of pieces
    • update frequency
    • are updates likely to happen on more then one subitem?
    • ...

    I would optimize for the viewing of the site, because it happens a lot more frequent than making a change, I suppose. So I would cache it in one file.

    The only way to know, is to measure it... with the microtime()-function, you can compare the script executiontime on different points and during different tryouts...