diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2007-11-27 00:58:09 +0100 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2007-11-27 00:58:09 +0100 |
commit | 905478e913aa51469c79f8a52d4f5e833004419b (patch) | |
tree | 1f5cf0bad631593cc5524fe8b7bc780bcef1b01a | |
parent | 0a7345dfa8a6d061e13394fdbe31c77231f1847c (diff) |
Tune caching functionality a bit.
-rw-r--r-- | lib/LXRng/Cached.pm | 24 | ||||
-rw-r--r-- | lib/LXRng/Markup/Dir.pm | 2 | ||||
-rw-r--r-- | lib/LXRng/Repo/Git.pm | 6 | ||||
-rw-r--r-- | lib/LXRng/Repo/Git/Directory.pm | 6 |
4 files changed, 25 insertions, 13 deletions
diff --git a/lib/LXRng/Cached.pm b/lib/LXRng/Cached.pm index f11a749..98ef152 100644 --- a/lib/LXRng/Cached.pm +++ b/lib/LXRng/Cached.pm @@ -13,9 +13,10 @@ BEGIN { }; if ($@ eq '') { $memcached = Cache::Memcached->new({ - 'servers' => ['127.0.0.1:11211']}); + 'servers' => ['127.0.0.1:11211'], + 'namespace' => 'lxrng'}); $memcached = undef - unless ($memcached->set(':lxrng_caching' => 1)) + unless ($memcached->set(':caching' => 1)) } } @@ -35,23 +36,22 @@ sub LXRng_Cached_cached(&;@) { if ($LXRng::Cached::memcached) { my ($pkg, $file, $line) = caller(0); my $params; - if (@args > 0) { - $params = Storable::freeze(\@args); - } - else { + unless (@args > 0) { my @caller = caller(1); - $params = Storable::freeze(\@DB::args); + @args = map { UNIVERSAL::can($_, 'cache_key') ? $_->cache_key : $_ + } @DB::args; } - my $key = ':lxrng:'. - Digest::SHA1::sha1_hex(join("\0", $file, $line, $params)); + $params = Storable::freeze(\@args); + + my $key = Digest::SHA1::sha1_hex(join("\0", $file, $line, $params)); my $val = $LXRng::Cached::memcached->get($key); unless ($val) { $val = [$func->()]; - $LXRng::Cached::memcached->set($key, $val); - warn "cache miss for $key"; + $LXRng::Cached::memcached->set($key, $val, 3600); + warn "cache miss for $key (".join(":", $file, $line, @args).")\n"; } else { - warn "cache hit for $key"; + warn "cache hit for $key\n"; } return @$val; } diff --git a/lib/LXRng/Markup/Dir.pm b/lib/LXRng/Markup/Dir.pm index b7743ee..f7a0a5f 100644 --- a/lib/LXRng/Markup/Dir.pm +++ b/lib/LXRng/Markup/Dir.pm @@ -58,7 +58,7 @@ sub listing { } } \@list; - } $$self{'node'}; + } $$self{'node'}->cache_key; } 1; diff --git a/lib/LXRng/Repo/Git.pm b/lib/LXRng/Repo/Git.pm index 757da26..3619427 100644 --- a/lib/LXRng/Repo/Git.pm +++ b/lib/LXRng/Repo/Git.pm @@ -30,6 +30,12 @@ sub new { return bless({root => $root, %args}, $class); } +sub cache_key { + my ($self) = @_; + + return $$self{'root'}; +} + sub _release_timestamp { my ($self, $release) = @_; diff --git a/lib/LXRng/Repo/Git/Directory.pm b/lib/LXRng/Repo/Git/Directory.pm index 592e608..1fdcc32 100644 --- a/lib/LXRng/Repo/Git/Directory.pm +++ b/lib/LXRng/Repo/Git/Directory.pm @@ -12,6 +12,12 @@ sub new { $class); } +sub cache_key { + my ($self) = @_; + + return $$self{'repo'}->cache_key.":".$$self{'ref'}; +} + sub time { my ($self) = @_; |