Created
September 4, 2021 00:40
-
-
Save hrkokw/fac0d5ded111627bd7c533400135089f to your computer and use it in GitHub Desktop.
Blosxom cacheentries plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: perl -*- | |
# vim: syntax=perl | |
# | |
# https://88171.net/blosxom-cacheentries-plugin | |
package cacheentries; | |
use Storable qw(lock_store lock_retrieve); | |
use File::stat; | |
use strict; | |
use warnings; | |
my $interval = (60 * 60 * 24) * 1; | |
my $storefile = sprintf("%s/%s.storable", $blosxom::plugin_state_dir, __PACKAGE__); | |
my $blosxom_entries = sub{}; | |
sub start { | |
return 1; | |
} | |
sub entries { | |
$blosxom_entries = $blosxom::entries; | |
return sub { | |
my @hashes; | |
if ( !_rebuild_required() ) { | |
eval { | |
@hashes = @{ lock_retrieve($storefile) } or die $!; | |
}; | |
return @hashes unless $@; | |
warn $@; | |
} | |
@hashes = &$blosxom_entries(); | |
lock_store(\@hashes, $storefile); | |
return @hashes; | |
}; | |
} | |
sub _rebuild_required { | |
return 1 unless my $st = stat($storefile); | |
return 1 unless time() < ($st->mtime + $interval); | |
return 0; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment