Hi,
I've bumped into this problem a few times now, and I can't seem to find a solution that is satisfactory. I have a web application that uses MySQL and Class::DBI, and it's sloooow, probably because of an overly busy webserver.
The application characteristics are such that writes are few, and most will be limited to a few tables. Reads will be more frequent so caching the results on the webserver might make sense (to me at least). So I was thinking of using something like Cache::Cache (which I can recommend), where I can map every table in the database to a 'namespace', use primary keys from the database as keys for the cache lookups, or use Class::DBI::Cacheable.
My main concern here is the algorithm for cache-replacement/update (or however you call it). Since my tables won't be updated a lot, periodically querying the database if a table is updated, and if so cleaning all cached info for this table seems a logical choice for me. I've been googling and cpan-ing a bit and haven't found any prior work on this, so either my idea is stupid or I've not searched hard enough.
I've been looking into the best way to do this in MySQL 3.23, I've seen 4.1 has some kind of table checksumming that could be used to see if a table is changed, and 5 versions have a statistics schema that could be used, but I can't find anything for MySQL 3.23. The best things I could think of are:
- writing some kind of daemon on the database-server that updates some kind of statistics database with the modification times of the actual database files on disk.
- write some wrapper in Class::DBI that updates a statistics table whenever an insert/update/delete is done in the database, and have my cache query this statistics table.
Anybody know of any modules that implement something like this, or other suggestions on how to do caching in this type of situation? (I can't change apache config, mysql version or web server hardware btw., at least not in the near future)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.