diff options
Diffstat (limited to 'lib/TgLib/Cache.pm')
-rw-r--r-- | lib/TgLib/Cache.pm | 34 |
1 files changed, 34 insertions, 0 deletions
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<store retrieve>; +use File::Basename qw<dirname>; + +use TgLib::Env qw<$CACHE_HOME>; + +use parent qw<Exporter>; +our @EXPORT = qw<new>; + +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; |