Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Bitten by the worst case (or why it pays to know whats inside the black box)

by dws (Chancellor)
on Jun 26, 2004 at 16:58 UTC ( [id://369842]=note: print w/replies, xml ) Need Help??


in reply to Bitten by the worst case (or why it pays to know whats inside the black box)

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:

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 );
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.

  • Comment on Re: Bitten by the worst case (or why it pays to know whats inside the black box)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found