CHI-Cascade

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
      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

README  view on Meta::CPAN

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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 )

README  view on Meta::CPAN

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
        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

547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
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

706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
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

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
        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 )