Skip to content

Commit

Permalink
get_keys not supported in File driver when key_digest is used, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jonswar committed Nov 23, 2009
1 parent b217a7c commit beed76e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Revision history for CHI

0.32 Nov 17, 2009

* Fixes
- get_keys not supported in File driver when key_digest is used, for now

0.31 Nov 17, 2009

* Improvements
Expand Down
9 changes: 8 additions & 1 deletion lib/CHI/Driver/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ sub clear {
sub get_keys {
my ($self) = @_;

die "get_keys not supported when key_digest is set"
if $self->key_digest;

my @filepaths;
my $wanted = sub { push( @filepaths, $_ ) if -f && /\.dat$/ };
my @keys = $self->_collect_keys_via_file_find( \@filepaths, $wanted );
Expand All @@ -158,6 +161,9 @@ sub get_keys {
sub _collect_keys_via_file_find {
my ( $self, $filepaths, $wanted ) = @_;

die "cannot retrieve keys from filenames when key_digest is set"
if $self->key_digest;

my $namespace_dir = $self->path_to_namespace;
return () if !-d $namespace_dir;

Expand Down Expand Up @@ -336,7 +342,8 @@ Digest algorithm to use on the key before storing - e.g. "MD5", "SHA-1", or
Can be a L<Digest|Digest> object, or a string or hashref which will passed to
Digest->new(). You will need to ensure Digest is installed to use these
options.
options. Also, L<CHI/get_keys> is currently not supported when a digest is
used, this will hopefully be fixed at a later date.
By default, no digest is performed and the entire key is used in the filename,
after escaping unsafe characters.
Expand Down
4 changes: 3 additions & 1 deletion xt/release/file-digest.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use strict;
use warnings;
use File::Basename;
use File::Temp qw(tempdir);
use Test::More tests => 1;
use Test::More tests => 2;
use Test::Exception;
use CHI;

my $root_dir = tempdir( "file-digest-XXXX", TMPDIR => 1, CLEANUP => 1 );
Expand All @@ -19,3 +20,4 @@ my $cache = CHI->new(
my $key = scalar( 'ab' x 256 );
my $file = basename( $cache->path_to_key($key) );
is( $file, 'db62ffe116024a7a4e1bd949c0e30dbae9b5db77.sha', 'SHA-1 digest' );
throws_ok { $cache->get_keys() } qr/get_keys not supported when key_digest is set/;

0 comments on commit beed76e

Please sign in to comment.