Subject: | An option to disable the cache. |
While patching Parse::BACKPAN::Packages I found myself duplicating code
because of this:
if ( !$self->no_cache ) {
my $cache = App::Cache->new( { ttl => 60 * 60 } );
$self->files(
$cache->get_code( 'files', sub { $self->_init_files() } ) );
$self->dists_by(
$cache->get_code( 'dists_by', sub { $self->_init_dists_by()
} ) );
} else {
$self->files( $self->_init_files() );
$self->dists_by( $self->_init_dists_by() );
}
What if instead you could tell the $cache to disable itself? It would
cause get_code() to not check the cache and just use the code.
Similarly, get_url() would fetch the url. That would reduce the above to:
my $cache = App::Cache->new( { ttl => 60 * 60 } );
$cache->enabled(0) if $self->no_cache;
$self->files(
$cache->get_code( 'files', sub { $self->_init_files() } )
);
$self->dists_by(
$cache->get_code( 'dists_by', sub { $self->_init_dists_by() } )
);
Let me know and I'll put together a patch.