Skip to content

Instantly share code, notes, and snippets.

@issm
Created December 7, 2011 09:21
Show Gist options
  • Save issm/1442136 to your computer and use it in GitHub Desktop.
Save issm/1442136 to your computer and use it in GitHub Desktop.
2011-12-07.cache-filecache
use 5.12.0;
use warnings;
use FindBin;
use File::Find;
use Storable qw/thaw/;
use Data::Dumper;
my $target = "${FindBin::Bin}/cache";
sub _do_something {
my ($f) = @_;
my ($raw, $data);
$raw = do {
my $a;
local $/;
open my $fh, '<', $f or die $!;
$a = <$fh>;
close $fh;
$a;
};
$data = thaw($raw);
say Dumper $data;
}
sub _handle_found {
my $f = $File::Find::name;
return if -d $f;
return _do_something($f);
}
find \&_handle_found, $target;
use 5.12.0;
use warnings;
use FindBin;
use Cache::FileCache;
my $cache = Cache::FileCache->new({
cache_root => "${FindBin::Bin}/cache",
namespace => 'mycache',
});
$cache->set(
'hogehoge',
{ foo => 1, bar => 2, baz => [ 3, 4, 5 ] },
600,
);
$cache->set(
'fugafuga',
[qw/ a b c d e /],
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment