The other day I realized that I needed to implement a auto-expiring file cache to store some infrequently changing remote data.
I immediately went to CPAN and did a search on "cache expire" and looked at the first result Cache.
The example was clear and exactly what i needed to implement. Literally 5 minutes later I had my code working and passing tests.
I can think of no other language where the solving of a problem of this complexity would take so little time from realizing the need to implementation. Nor can I think of another language where I could implement the entire solution in 4 lines of my own code. Nor another language where I would have the confidence to use a third-party library without spending a lot of time looking through the implementation to verify its quality. With CPAN I inherently trust the quality of modules.
I know I'm preaching to the choir here, but I get so much joy out of Perl that sometime I need to sing out its praises
In case anyone is interested, here is the code:
use Cache::File;
...
has _cache => (isa => 'Cache', is => 'rw', default => sub{ new Cache::
+File(cache_root => '/tmp/cacheroot')});
...
my $value = $self->_cache->get($key);
unless ($value) {
$value = do_operation(...);
$self->_cache->set($key,'1 hour');
}
return $value;
-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
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.