EntryFullTextのキャッシュを自動削除

nobu@shibuya.plゲット! yappoさんありがとう!!

ということで、100Tipsに向けて、以前から気になっていたEntryFullTextのキャッシュを自動削除するパッチを作成してみました。


本当はauto_purgeで実装したかったのですが、うまく動かせませんでした。

 --- svn/plagger/lib/Plagger/Cache.pm    (リビジョン 941)
+++ svn/plagger/lib/Plagger/Cache.pm (作業コピー)
@@ -14,6 +14,7 @@
$conf->{class} ||= 'Cache::FileCache';
$conf->{params} ||= {
cache_root => File::Spec->catfile($conf->{base}, 'cache'),
+ default_expires_in => $conf->{expires} || 'never',
};

$conf->{class}->require;
@@ -56,6 +57,7 @@
my $hit_miss = defined $value ? "HIT" : "MISS";
Plagger->context->log(debug => "Cache $hit_miss: $_[0]");

+ $self->{cache}->purge();
$value;
}

設定は以下の通り。一週間経つと自動で削除します。実行時間は少し長くなるでしょうが、これで容量的にも安心です。

global:
cache:
expires: 604800

expiresの単位は以下が使用できるようです。


e.g., "10 minutes". The valid units are s, second, seconds, sec, m, minute, minutes, min, h, hour, hours, d, day, days, w, week, weeks, M, month, months, y, year, and years