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."