15 Jan 2022 06:44:58 UTC
- Distribution: Data-Tubes
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (279 / 0 / 0)
- KwaliteeBus factor: 1
- 83.80% Coverage
- License: artistic_2
- Perl: v5.10.0
- Activity24 month
- Download (141.47KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- CLASS METHODS
- ACCESSOR METHODS
- BUSINESS LOGIC METHODS
- SEE ALSO
- COPYRIGHT AND LICENSE
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).
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
@argis ignored. Returns
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);
$valuecorresponding to the
$keyin the cache, overriding any previous value or creating a new item. Any additional argument in
@argsis ignored. Returns
Data::Tubes is a valid entry point of all of this.
CHI for a comprehensive caching library.
Flavio Poletti <email@example.com>
Copyright (C) 2016 by Flavio Poletti <firstname.lastname@example.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.