Lab::Moose::Instrument::Cache - Device caching functionality in Moose::Instrument drivers
version 3.653
in your driver:
use Lab::Moose::Instrument::Cache; cache foobar => (getter => 'get_foobar'); sub get_foobar { my $self = shift; return $self->cached_foobar( $self->query(command => ...)); } sub set_foobar { my ($self, $value) = @_; $self->write(command => ...); $self->cached_foobar($value); }
This package exports a new Moose keyword: cache.
Calling cache key => (getter => $getter, isa => $type) generates the following functions:
cache key => (getter => $getter, isa => $type)
cached_key
Calling $instr->cached_key() will return the last stored value from the cache. If the cache entry is empty, use the $getter method.
$instr->cached_key()
$getter
To update the cache entry, call $instr->cached_key($value).
$instr->cached_key($value)
has_cached_key
Return true if the cache entry holds a value (which is not undef).
clear_cached_key
Clear the value of the cache entry.
cached_key_builder
Called by cached_key if the entry is cleared. This will call the $getter method. Can be overriden by 'around' method modifier if the $getter needs special extra arguments.
The isa argument is optional.
isa
Some methods take an additional parameter (e.g. channel number). For this case you can give the index_arg argument to the cache keyword:
index_arg
cache foobar => (isa => 'Num', getter => 'get_foobar', index_arg => 'channel'); # Get value from cache. my $value = $instr->cached_foobar(channel => 1); # Store value. $instr->cached_foobar(channel => 2, value => 1.234); # Clear single entry. $instr->clear_cached_foobar(channel => 3); # Clear them all. $instr->clear_cached_foobar(); # Check for cache value if ($instr->has_cached_foobar(channel => 1)) {...}
This software is copyright (c) 2018 by the Lab::Measurement team; in detail:
Copyright 2016 Simon Reinhardt 2017 Andreas K. Huettel, Simon Reinhardt 2018 Simon Reinhardt
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Lab::Measurement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Measurement
CPAN shell
perl -MCPAN -e shell install Lab::Measurement
For more information on module installation, please visit the detailed CPAN module installation guide.