Arunbear has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a cgi program that is using Sqlite for data storage. The database is only updated about once per week and I'm thinking about using caching to reduce the load on the DB. What are the pros and cons of caching at the HTTP level vs the application level (e.g. using Cache::Cache)?

Thanks for sharing your thoughts.
  • Comment on What's the best way to cache dynamic web content?

Replies are listed 'Best First'.
Re: What's the best way to cache dynamic web content?
by Corion (Patriarch) on May 10, 2004 at 10:53 UTC

    If the data changes only "about" once per week, use make or whatever other dependency tool you like to create a static HTML version of the site or the static parts of it.

    To indicate that site recreation is necessary, you could make the data insertion tool recreate the whole site or you could set up an Apache ErrorHandler, which recreates the "missing" file - a database update would simply wipe the HTML documents from existence. You could also have a nightly cron job running that recreates the whole site from the DB, possibly only when neccessary.

Re: What's the best way to cache dynamic web content?
by exussum0 (Vicar) on May 10, 2004 at 11:04 UTC
Re: What's the best way to cache dynamic web content?
by perrin (Chancellor) on May 10, 2004 at 15:01 UTC
    Caching at the HTTP level is much more efficient. If you publish your data as static files, you allow the web server to work in the most efficient way possible. You can also use a caching proxy like apache's mod_proxy module.

    Caching in the application gives you more control, and allows you to cache just a part of a page instead of the entire thing. I would recommend you look at Cache::FastMmap instead of Cache::Cache, because it's much faster.

      Say, how much faster is Cache::FastMmap than the other available cache modules on CPAN? That sounds like a good topic for an article...

      -sam

        Yeah yeah.... I have to finish my talk for YAPC first, because it's only about a month away. But, FYI, it's about 7 times as fast.