Skip to content

Instantly share code, notes, and snippets.

@hrkokw
Created September 4, 2021 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrkokw/fac0d5ded111627bd7c533400135089f to your computer and use it in GitHub Desktop.
Save hrkokw/fac0d5ded111627bd7c533400135089f to your computer and use it in GitHub Desktop.
Blosxom cacheentries plugin
# -*- 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