CHI-Cascade
view release on metacpan or search on metacpan
save a value by some reasons for example)
0.12 2011-11-14
- More stable version as i think ;-) Please use it
- Improved signal handling in tests (for memcached killing)
- Fixed bug - dependencies as sub {} didn't get a qr_params properly
- Fixed rule's bug
0.11 2011-11-14
- Fixed bug (sometime dead locks were after target locking)
- Added 'busy_lock' option in contructor and to 'rule' method
- All 'set's in cache executed with expire as 'never' (excluding locking of
targets)
0.1 2011-11-14
- Changed API of execution 'code' of rules
- Now you can use instances of CHI::Cascade::Rule in your target codes
- Now you can pass any parameters to target codes described in rules
0.05 2011-11-12
- More improved the test t/03_memcached_multi.t
CONSTRUCTOR
$cascade = CHI::Cascade->new( %options )
This method constructs a new "CHI::Cascade" object and returns it.
Key/value pair arguments may be provided to set up the initial state.
Options are:
chi Required. Instance of CHI object. The CHI::Cascade doesn't construct
this object for you. Please create instance of "CHI" yourself.
busy_lock
Optional. Default is *never*. *This is not "busy_lock" option of
CHI!* This is amount of time (to see "DURATION EXPRESSIONS" in CHI)
until all target locks expire. When a target is to being computing
it is locked. If process which is to be computing target and it will
die or OS will be hangs up we can dead locks and locked target will
never recomputed again. This option helps to avoid it. You can set
up a special busy_lock for rules too.
target_chi
Optional. This is CHI cache for target markers. Default value is
value of "chi" option. It can be useful if you use a "l1_cache" in
CHI option. So you can separate data of targets from target markers
- data will be kept in a file cache and a marker in memory cache for
example.
METHODS
rule( %options )
valid values of all dependencies of current target before
execution of this code the last will not be executed (The
"run" will return "undef").
params
Optional. You can pass in your code any additional parameters by
this option. These parameters are accessed in your rule's code
through "params" in CHI::Cascade::Rule method of
CHI::Cascade::Rule instance object.
busy_lock
Optional. Default is "busy_lock" of constructor or *never* if
first is not defined. *This is not "busy_lock" option of CHI!*
This is amount of time (to see "DURATION EXPRESSIONS" in CHI)
until target lock expires. When a target is to being computed it
is locked. If process which to be recomputing a target and it
will die or OS will be hangs up we can dead locks and locked
target will never recomputed again. This option helps to avoid
it.
recomputed
Optional. This is a computational callback (coderef). If target
of this rule was recomputed this callback will be executed right
lib/CHI/Cascade.pm view on Meta::CPAN
Key/value pair arguments may be provided to set up the initial state.
Options are:
=over
=item chi
B<Required>. Instance of L<CHI> object. The L<CHI::Cascade> doesn't construct this
object for you. Please create instance of C<CHI> yourself.
=item busy_lock
B<Optional>. Default is I<never>. I<This is not C<busy_lock> option of CHI!>
This is amount of time (to see L<CHI/"DURATION EXPRESSIONS">) until all target
locks expire. When a target is to being computing it is locked. If process which
is to be computing target and it will die or OS will be hangs up we can dead
locks and locked target will never recomputed again. This option helps to avoid
it. You can set up a special busy_lock for rules too.
=item target_chi
B<Optional>. This is CHI cache for target markers. Default value is value of
L</chi> option. It can be useful if you use a L<CHI/l1_cache> option. So you can
separate data of targets from target markers - data will be kept in a file cache
and a marker in memory cache for example.
=back
lib/CHI/Cascade.pm view on Meta::CPAN
last will not be executed (The C<run> will return C<undef>).
=back
=item params
B<Optional>. You can pass in your code any additional parameters by this option.
These parameters are accessed in your rule's code through
L<CHI::Cascade::Rule/params> method of L<CHI::Cascade::Rule> instance object.
=item busy_lock
B<Optional>. Default is L</busy_lock> of constructor or I<never> if first is not
defined. I<This is not C<busy_lock> option of CHI!> This is amount of time (to
see L<CHI/"DURATION EXPRESSIONS">) until target lock expires. When a target is
to being computed it is locked. If process which to be recomputing a target and
it will die or OS will be hangs up we can dead locks and locked target will
never recomputed again. This option helps to avoid it.
=item recomputed
B<Optional>. This is a computational callback (coderef). If target of this rule
was recomputed this callback will be executed right away after a recomputed
value has been saved in cache. The callback will be executed as $coderef->(
lib/CHI/Cascade/Rule.pm view on Meta::CPAN
my $from = ref($class) ? $class : \%opts;
$opts{depends} = [ defined( $opts{depends} ) ? ( $opts{depends} ) : () ]
unless ref( $opts{depends} );
# To do clone or new object
my $self = bless {
map( { $_ => $from->{$_} }
grep { exists $from->{$_} }
qw( target depends depends_catch code params busy_lock cascade recomputed actual_term ttl value_expires ) ),
qr_params => [],
matched_target => undef
}, ref($class) || $class;
if ( $opts{run_instance} ) {
$self->{run_instance} = $opts{run_instance};
weaken $self->{run_instance}; # It is against memory leaks
}
weaken $self->{cascade}; # It is against memory leaks
lib/CHI/Cascade/Rule.pm view on Meta::CPAN
return $self;
}
( ref $self->{value_expires} eq 'CODE' ? $self->{value_expires}->( $self ) : $self->{value_expires} ) // 'never';
}
sub target_expires {
my ( $self, $trg_obj ) = @_;
$trg_obj->locked
?
$self->{busy_lock} || $self->{cascade}{busy_lock} || 'never'
:
$trg_obj->expires // $trg_obj->expires( $self->value_expires );
}
sub ttl {
my $self = shift;
return undef
unless exists $self->{ttl};
( run in 0.416 second using v1.01-cache-2.11-cpan-05444aca049 )