Cache::File で Storable
2006-10-24-6 
[Programming]
勉強になります。
[を] Data::Dumper で eval するメモ[2006-10-24-2]
に対して、
404 Blog Not Found:perl - Cache::File と Storable
http://blog.livedoor.jp/dankogai/archives/50668036.html
とのこと。ありがとうございます。
thaw, freeze ってこういう用途に使うものなのですね。
調べが足りなく反省。しかし、教えていただいてツイてる!
以下、「学んだら作る」サンプルプログラム:
は取り出します。
 [を] Data::Dumper で eval するメモ[2006-10-24-2]
Cache::FileでStoreblaを使いたいのだが、できそうもないので
(何か良い方法があったら教えて下さい)、
に対して、
404 Blog Not Found:perl - Cache::File と Storable
http://blog.livedoor.jp/dankogai/archives/50668036.html
出来ます、というよりCacheははじめからStorableをサポートしてます。
とのこと。ありがとうございます。
thaw, freeze ってこういう用途に使うものなのですね。
調べが足りなく反省。しかし、教えていただいてツイてる!
以下、「学んだら作る」サンプルプログラム:
#!/usr/bin/perl
use strict;
use warnings;
use Cache::File;
my $cache = Cache::File->new(cache_root => "/var/tmp/cache",
                             default_expires => '1 hour');
my $foo = $cache->thaw("test");
if ($foo) {
    print "out : ";
} else {
    print "in : ";
    $foo = [ 0, [1,2,3], "hello", {one => 1, two => 2} ];
    $cache->freeze("test", $foo);
}
#$cache->clear();
print $foo->[0], " ";
print join(",", @{$foo->[1]}), " ";
print $foo->[2], " ";
print join(",", map {"$_:$foo->[3]{$_}"} keys %{$foo->[3]}), "\n";
以下、実行結果。一回目の実行でキャッシュに入れて、それ以降の実行では取り出します。
% perl test.pl in : 0 1,2,3 hello one:1,two:2 % perl test.pl out : 0 1,2,3 hello one:1,two:2 % perl test.pl out : 0 1,2,3 hello one:1,two:2
この記事に言及しているこのブログ内の記事
 
