Subject: | CHI::Driver::File - speed up get_keys() function |
I use File driver in situations when I have a small amount of keys, but
I often call get_keys(). Even when we use L1_CACHE, get_keys() calls
find(). More over, the subdirs is never deletes via this driver.
So, we call often get_keys() which calls find() on every subdir in the
directory where keys stored. I wrote a micro patch, which can be useful
for people with same situation. I don't know about overhead on scalar
function, but I consider it is better then we are calling filesystem
functions every time.
I put here full code to easy understanding and discuss:
my $is_empty = 0;
sub get_keys {
my ($self) = @_;
return () if ($is_empty);
my @filepaths;
my $re = quotemeta($self->file_extension);
my $wanted = sub { push( @filepaths, $_ ) if -f && /${re}$/ };
my @keys = $self->_collect_keys_via_file_find( \@filepaths,
$wanted );
$is_empty = (scalar @keys) ? 0 : 1;
return @keys;
}
Much better will be store results somewhere and just look for
modifications, but then in situations where a lot of keys CHI will eat
more memory. What are you say about this patch?