I'm in the middle of moving away from PyroCMS to a custom solution built on Laravel. Wont go into the details as to why here, but it is a necessity.

I'm toying with the idea of caching things like pages and posts into flatfile once they are created, and then loading them (if they exist) and falling back to the mysql database if the cache isnt found.

It got me thinking. Is there a problem with essentially running the entire 'frontend' of your system or site on flatfile, pre-rendered cached files? Surely the cache only needs dropping/replacing when a post or page is modified, so a cache could essentially be kept for the lifetime of the site.

Unless I'm missing something, surely this is something that should be done a lot more, should it not? Even if it was just storing serialised or json data from the database tables, it's got to be faster than opening up a mysql connection hasn't it?

  • 2
    The only way to know for sure whether it's faster or not is to test it. Know that this kind of caching is an optimization step because you still need to function when the cache misses. The first rule of Optimization is "DON'T". The second rule is to carefully measure your system first so you know you're optimizing that 20% of your code that's causing 80% of all your bottlenecks. May 9 '13 at 16:15
  • 3
    Shouldn't a sufficiently well-configured reverse-proxy be able to do this automatically for you, maybe even in-memory for even lower response time?
    – Philipp
    May 9 '13 at 16:53

As per comments, before doing optimisations, you have to know which parts need to be optimised (measure). For static files, you can use reverse proxy. If latency is your problem, then moving files to a CDN might help with geographically distant clients. These optimisations will free you from programming, less code and even faster because they're done even before php run.

Then for the dynamic parts you can cache as needed. One thing with using files is if in the future you want add more servers, accessing the cache files won't be as ideal as using memcache, for example. Still worth doing on frontend, e.g. for showing data as user types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.