From 47fb4fc02407def9d9b19a2746983b8c65937e3f Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 24 Jun 2019 12:04:15 +0200 Subject: TgLib.{Cache,Env} --- lib/TgLib/Cache.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/TgLib/Cache.pm (limited to 'lib/TgLib/Cache.pm') diff --git a/lib/TgLib/Cache.pm b/lib/TgLib/Cache.pm new file mode 100644 index 0000000..d3723b7 --- /dev/null +++ b/lib/TgLib/Cache.pm @@ -0,0 +1,34 @@ +package TgLib::Cache; + +use Storable qw; +use File::Basename qw; + +use TgLib::Env qw<$CACHE_HOME>; + +use parent qw; +our @EXPORT = qw; + +my $CACHE_FILE = "$CACHE_HOME/tgutils/cache"; + +sub new { + my $class = shift; + + # Fetch cache + return bless((-f $CACHE_FILE + ? retrieve($CACHE_FILE) + : {'version' => $main::VERSION}), $class); +} + +sub offset { + my $cache = shift; + $cache->{'offset'} = shift if @_; + return $cache->{'offset'}; +} + +sub save { + my $cache = shift; + mkdir dirname $CACHE_FILE; + store($cache, $CACHE_FILE); +} + +1; -- cgit v1.2.3