Skip to content

Commit

Permalink
Item13525: add a low-level disk cache
Browse files Browse the repository at this point in the history
... to mitigate readFile() being called redundantly
  • Loading branch information
MichaelDaum committed Jul 17, 2015
1 parent 36aca0d commit 5735e2d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
Expand Up @@ -152,6 +152,7 @@ sub finish {
undef $this->{web};
undef $this->{topic};
undef $this->{attachment};
undef $this->{cache};
}

# Used in subclasses for late initialisation during object creation
Expand Down Expand Up @@ -1113,14 +1114,20 @@ sub saveFile {
close($fh)
or throw Error::Simple(
'Rcs::Handler: failed to close file ' . $name . ': ' . $! );

$this->{cache}{$name} = undef;

return;
}

# Used by subclasses
sub readFile {
my ( $this, $name ) = @_;
ASSERT($name) if DEBUG;
my $data;

my $data = $this->{cache}{$name};
return $data if defined $data;

my $IN_FILE;

# Note: no IO layer; we want to trap encoding errors
Expand All @@ -1130,6 +1137,9 @@ sub readFile {
$data = <$IN_FILE>;
close($IN_FILE);
}

$this->{cache}{$name} = $data;

return $data;
}

Expand Down

0 comments on commit 5735e2d

Please sign in to comment.