Data::Tubes::Util::Cache
Simple class for handling caching. The interface is compatible with that of CHI for methods used by "cache" in Data::Tubes::Plugin::Plumbing, so it is provided as a simple replacement in case you don't have, or don't want to use, CHI.
The class implements both an in-memory and a on-filesystem caches, depending on what you set as parameter repository. A hash reference means caching in memory; a directory name means caching on file (the directory will be created if not existent).
repository
The class is realized via Mo. You can extend it, to a certain degree.
my cache = Data::Tubes::Util::Cache->new(%args);
constructor for the class. See "ACCESSOR METHODS" for the accepted arguments.
$cache->repository($href); $href = $cache->repository();
set/retrieve the repository for the cache. It can be either of:
an hash reference, in which case the cache is kept in memory;
a directory name, in which case the cache is kept in the filesystem.
Defaults to an empty hash.
$cache->max_items($n); $n = $cache->max_items();
set/retrieve the maximum numbers of elements you want to store in the cache. When set to a false value, the limitation is disabled.
Used by "purge".
$item = $cache->get($key, @args);
get the item related to $key, taking it from the cache. Any additional argument in @arg is ignored. Returns undef if the $key is missing.
$key
@arg
undef
$cache->purge();
cleanup the cache. If the value of "max_items" is not true, this method does nothing. Otherwise, elements are removed from the cache until the number of items is less than, or equal to, the maximum number set.
$cache->set($key, $value, @args);
set the $value corresponding to the $key in the cache, overriding any previous value or creating a new item. Any additional argument in @args is ignored. Returns $value.
$value
@args
Data::Tubes is a valid entry point of all of this.
CHI for a comprehensive caching library.
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2016 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Data::Tubes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Tubes
CPAN shell
perl -MCPAN -e shell install Data::Tubes
For more information on module installation, please visit the detailed CPAN module installation guide.