Skip Menu |

This queue is for tickets about the App-Cache CPAN distribution.

Report information
The Basics
Id: 52302
Status: resolved
Priority: 0/
Queue: App-Cache

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.36
Fixed in: (no value)



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.
Good point. App-Cache 0.37 just hit CPAN which you can disable: =item * enabled can be set to 0 for testing, in which case you will always get cache misses: my $cache = App::Cache->new({ enabled => 0 }); =back Thanks! Leon