When using locking to ensure that only one process is generating data and updating cache, there is no need to use File::Temp for temporary file. This should improve performance. The _tempfile_to_path subroutine got promoted to _tempfile_to_path method, because we want to choose correct one dynamically, based on the type of object (polymorphism). Idea-inspired-by-code-by: John 'Warthog9' Hawley <warthog9@xxxxxxxxxx> Signed-off-by: Jakub Narebski <jnareb@xxxxxxxxx> --- In previous version of this patch _tempfile_to_path was subroutine rather than method... which mans that GitwebCache::SimpleFileCache version was being picked up because that is the package where methods that use it are. "Gitweb caching v7" either writes directly to cache entry file, or uses file with name based on original cache entry as temporary output file; the latter is just like GitwebCache::FileCacheWithLocking does it after this patch. gitweb/lib/GitwebCache/FileCacheWithLocking.pm | 16 ++++++++++++++++ gitweb/lib/GitwebCache/SimpleFileCache.pm | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gitweb/lib/GitwebCache/FileCacheWithLocking.pm b/gitweb/lib/GitwebCache/FileCacheWithLocking.pm index 1ea0e60..4d8114d 100644 --- a/gitweb/lib/GitwebCache/FileCacheWithLocking.pm +++ b/gitweb/lib/GitwebCache/FileCacheWithLocking.pm @@ -46,6 +46,22 @@ sub get_lockname { return $lockfile; } +# ---------------------------------------------------------------------- +# "private" utility functions and methods + +# take a file path to cache entry, and its directory +# return filehandle and filename of open temporary file, +# like File::Temp::tempfile +sub _tempfile_to_path { + my ($self, $file, $dir) = @_; + + my $tempname = "$file.tmp"; + open my $temp_fh, '>', $tempname + or die "Couldn't open temporary file '$tempname' for writing: $!"; + + return ($temp_fh, $tempname); +} + # ...................................................................... # interface methods diff --git a/gitweb/lib/GitwebCache/SimpleFileCache.pm b/gitweb/lib/GitwebCache/SimpleFileCache.pm index 12af44f..aeb91d4 100644 --- a/gitweb/lib/GitwebCache/SimpleFileCache.pm +++ b/gitweb/lib/GitwebCache/SimpleFileCache.pm @@ -288,7 +288,7 @@ sub write_fh { # return filehandle and filename of open temporary file, # like File::Temp::tempfile sub _tempfile_to_path { - my ($file, $dir) = @_; + my ($self, $file, $dir) = @_; # tempfile will croak() if there is an error return tempfile("${file}_XXXXX", @@ -324,7 +324,7 @@ sub store { } # generate a temporary file - my ($temp_fh, $tempname) = _tempfile_to_path($file, $dir); + my ($temp_fh, $tempname) = $self->_tempfile_to_path($file, $dir); chmod 0666, $tempname or warn "Couldn't change permissions to 0666 / -rw-rw-rw- for '$tempname': $!"; @@ -466,7 +466,7 @@ sub set_coderef_fh { } # generate a temporary file - my ($fh, $tempfile) = _tempfile_to_path($path, $dir); + my ($fh, $tempfile) = $self->_tempfile_to_path($path, $dir); # code writes to filehandle or file $code->($fh, $tempfile); -- 1.7.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html