CHI-Cascade
view release on metacpan or search on metacpan
163164165166167168169170171172173174175176177178179180181182183
save a value by some reasons
for
example)
0.12 2011-11-14
- 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 pass any parameters to target codes described in rules
0.05 2011-11-12
- More improved the test t/03_memcached_multi.t
59606162636465666768697071727374757677787980818283848586CONSTRUCTOR
$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
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
)
202203204205206207208209210211212213214215216217218219220221222223224
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
547548549550551552553554555556557558559560561562563564565566567568569570571572573Key/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
706707708709710711712713714715716717718719720721722723724725726727728729last
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
111213141516171819202122232425262728293031my
$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
7677787980818283848586878889909192939495
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.320 second using v1.01-cache-2.11-cpan-05444aca049 )