[Catalyst] DB values that change very rarely
Dami Laurent (PJ)
laurent.dami at justice.ge.ch
Thu Jan 10 20:45:06 GMT 2013
>De : Jesse Sheidlower [mailto:jester at panix.com]
>Envoyé : jeudi, 10. janvier 2013 16:16
>À : catalyst at lists.scsys.co.uk
>Objet : [Catalyst] DB values that change very rarely
>In one of my apps, I have a number of tables that contain values that
>change very rarely.
>This means that almost every page generation hits the database a whole bunch of
>unnecessary times, and that all of my controllers are cluttered.
>This must be a fairly common problem. What's the best way to deal with
>it--both the desire to persist what is mostly static data, and to keep
>my controllers clean?
First of all, you need a piece of information that tells you if the configuration data has changed. It can be a version number or a timestamp column, either associated to each table (if these tables change individually), or in a global "version table" that covers everything. Every time that a power user edits such data, your version number or timestamp must be updated.
Or maybe all this configuration data that doesn't change very often could be stored, not in database, but in a config file (using YAML, XML, or Config::General). In that case you have the mtime of the file to tell you if the data has changed.
Based on this, your controller can use any of the CPAN caching modules to keep the data in memory; you still need to go to the datasource to check if the version number or timestamp has changed, but that's a much smaller request.
Hope this helps -- good luck,
More information about the Catalyst