Commit 2506ddaa authored by Roman Lacko's avatar Roman Lacko
Browse files

use shorter keys in cache

parent aef06aef
......@@ -13,39 +13,48 @@ sub new {
return bless {}, $class;
};
sub _uri_to_key {
my (undef, $uri) = @_;
return $uri->path . ":" . ($uri->query // "");
}
sub get {
my ($self, $uri) = @_;
my $p = $self->{data}->{$uri};
my $key = $self->_uri_to_key($uri);
my $p = $self->{data}->{$key};
if ($p) {
$log->trace("cache hit '$uri'");
$log->trace("etag '$p->[0]'");
$log->trace("cache seach hit '$key' etag '$p->[0]'");
return @$p;
}
$log->trace("cache miss '$uri'");
$log->trace("cache search miss '$key'");
return;
};
sub set {
my ($self, $uri, $tag, $data) = @_;
$self->{data}->{$uri} = [ $tag, $data ];
$log->trace("cache store '$uri'");
$log->trace("etag '$tag'");
my $key = $self->_uri_to_key($uri);
$self->{data}->{$key} = [ $tag, $data ];
$log->trace("cache store '$key' etag '$tag'");
# don't leak data
return;
};
sub flush {
my ($self, @uris) = @_;
$log->trace("cache flush '", join(",", @uris), "'");
my @keys = map { $self->_uri_to_key($_) } (grep { defined } @uris);
if (!@uris) {
$log->trace("cache flush all");
$self->{data} = {};
} else {
delete $self->{data}->{@uris};
$log->trace("cache flush " . join(",", map { "'$_'" } @keys))
if $log->is_trace;
delete $self->{data}->{@keys};
}
# don't leak old keys
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment