Unfortunately however due to an oversight on my behalf the caching was ineffective and I was never reusing the old data and was always regenerating the same data structures.
My brain has now been so warped by doing Test-Driven Development that when I hear of problems like this I immediately think "missing unit test!" and "what test could I have written while implementing caching to verify that the cache is effective?"
One simple approach is to expose some sort of "cache load" counter, then test to make sure that is or isn't incrementing, as appropriate. Something like the following is quick to write:
You might need a way to load know test data, but if you're developing repeatable unit tests, that's a problem you'll need to tackle at some point.my $old_cache_count = $db->cache_count(); my $data = $db->fetch('known key 1'); ok( $data, 'expected value for key 1' ); # we expect that to have caused a cache load my $new_cache_count = $db->cache_count(); ok( $new_cache_count, $old_cache_count + 1 ); $old_cache_count = $new_cache_count; $data = $db->fetch('known key 2'); ok( $data, 'expected value for key 2' ); # the cache shouldn't have reloaded ok( $db->cache_count(), $old_cache_count );
In reply to Re: Bitten by the worst case (or why it pays to know whats inside the black box)
by dws
in thread Bitten by the worst case (or why it pays to know whats inside the black box)
by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |