From: Chris W. <la...@us...> - 2004-11-28 00:12:05
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4347 Modified Files: Action.pm Log Message: add 'cache_expire' to property listing so the values get copied when we do a clone(); add debugging entries to better trace caching execution Index: Action.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Action.pm,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** Action.pm 8 Nov 2004 14:40:17 -0000 1.59 --- Action.pm 28 Nov 2004 00:11:52 -0000 1.60 *************** *** 141,145 **** unless ( $CONFIG_ACTIONS{ $name } ) { $log->is_debug && ! $log->debug( "Config action not found for '$name', creating..." ); my $impl_class = $action_info->{class}; if ( $impl_class ) { --- 141,146 ---- unless ( $CONFIG_ACTIONS{ $name } ) { $log->is_debug && ! $log->debug( "Action from configuration has not yet been created for ", ! "'$name', creating..." ); my $impl_class = $action_info->{class}; if ( $impl_class ) { *************** *** 147,151 **** eval "require $impl_class"; if ( $@ ) { ! my $msg = "Cannot include library '$impl_class': $@"; $log->error( $msg ); oi_error $msg; --- 148,153 ---- eval "require $impl_class"; if ( $@ ) { ! my $msg = "Cannot include library '$impl_class' to " . ! "implement action '$name': $@"; $log->error( $msg ); oi_error $msg; *************** *** 240,252 **** } # These checks will die if they fail -- let the error bubble up $self->_check_task_validity; $log->is_debug && ! $log->debug( "Task is valid, continuing" ); $self->_check_security; $log->is_debug && ! $log->debug( "Task security checked, continuing" ); # Check cache and return if found --- 242,256 ---- } + my $item_desc = '[' . $self->name . ': ' . $self->task . ']'; + # These checks will die if they fail -- let the error bubble up $self->_check_task_validity; $log->is_debug && ! $log->debug( "Action $item_desc is valid, continuing" ); $self->_check_security; $log->is_debug && ! $log->debug( "Action $item_desc security checked, continuing" ); # Check cache and return if found *************** *** 257,281 **** } $log->is_debug && ! $log->debug( "Cached data not found, continuing" ); my $method_ref = $self->_find_task_method; $log->is_debug && ! $log->debug( "Found task method ok, running" ); my $content = eval { $self->$method_ref }; if ( $@ ) { ! $log->warn( "Caught error from task: $@" ); $content = $@; } else { $log->is_debug && ! $log->debug( "Task executed ok, excuting filters" ); $self->notify_observers( 'filter', \$content ); $log->is_debug && ! $log->debug( "Filters ran ok, saving to cache" ); ! if ( my $cache_expire = $self->_is_using_cache ) { $self->_set_cached_content( $content, $cache_expire ); } } return $content; --- 261,293 ---- } $log->is_debug && ! $log->debug( "Cached data not found for $item_desc, continuing" ); my $method_ref = $self->_find_task_method; $log->is_debug && ! $log->debug( "Found task method for $item_desc ok, running" ); my $content = eval { $self->$method_ref }; if ( $@ ) { ! $log->warn( "Caught error from task $item_desc: $@" ); $content = $@; } else { $log->is_debug && ! $log->debug( "Task $item_desc executed ok, excuting filters" ); $self->notify_observers( 'filter', \$content ); $log->is_debug && ! $log->debug( "Filters for $item_desc ran ok, checking cacheable" ); ! my $cache_expire = $self->_is_using_cache; ! if ( $cache_expire ) { ! $log->is_debug && ! $log->debug( "This content is cacheable and has expiration ", ! "'$cache_expire'; caching content..." ); $self->_set_cached_content( $content, $cache_expire ); } + else { + $log->is_debug && + $log->debug( "Content from $item_desc not cacheable" ); + } } return $content; *************** *** 481,485 **** $log->is_debug && ! $log->debug( "Generating content for [", $self->name, "]" ); $content_params->{ACTION} = $self; --- 493,498 ---- $log->is_debug && ! $log->debug( "Generating content for [", $self->name, ": ", ! $self->task, "]" ); $content_params->{ACTION} = $self; *************** *** 555,560 **** sub initialize_cache_params { return undef } ! # Just ensure that every value is a number; also allow simple time ! # substitutions (e.g., '180m' or '3h' instead of '10800' seconds). sub cache_expire { --- 568,574 ---- sub initialize_cache_params { return undef } ! # Property: Just ensure that every value is a number; also allow ! # simple time substitutions (e.g., '180m' or '3h' instead of '10800' ! # seconds). sub cache_expire { *************** *** 573,579 **** } if ( $cache_info ) { ! $log->info( "Assigned cache expiration: ", ! join( '; ', map { "$_ = $self->{cache_expire}{ $_ }" } ! keys %{ $self->{cache_expire} } ) ); } return $self->{cache_expire}; --- 587,594 ---- } if ( $cache_info ) { ! $log->is_debug && ! $log->debug( "Assigned cache expiration for ", $self->name, ": ", ! join( '; ', map { "$_ = $self->{cache_expire}{ $_ }" } ! keys %{ $self->{cache_expire} } ) ); } return $self->{cache_expire}; *************** *** 624,630 **** } $tracking->{ $class } = []; ! $cache->set({ key => CACHE_CLASS_KEY, ! data => $tracking }); ! $log->is_debug && $log->debug( "Tracking data saved back" ); $log->is_info && $log->info( "Finished clearing cache for '$class'" ); return $num_cleared; --- 639,647 ---- } $tracking->{ $class } = []; ! $cache->set({ ! key => CACHE_CLASS_KEY, ! data => $tracking ! }); ! $log->is_debug && $log->debug( "Tracking data saved back to cache" ); $log->is_info && $log->info( "Finished clearing cache for '$class'" ); return $num_cleared; *************** *** 635,644 **** my ( $self ) = @_; my $expire = $self->cache_expire; ! return unless ( ref $expire eq 'HASH' ); ! my $time = $expire->{ $self->task } || $expire->{ CACHE_ALL_KEY() }; $log->is_debug && $log->debug( "Action/task ", $self->name, "/", $self->task, " ", ! "cached at time ", $time ); ! return $time; } --- 652,663 ---- my ( $self ) = @_; my $expire = $self->cache_expire; ! unless ( ref $expire eq 'HASH' ) { ! return; ! } ! my $expire_time = $expire->{ $self->task } || $expire->{ CACHE_ALL_KEY() }; $log->is_debug && $log->debug( "Action/task ", $self->name, "/", $self->task, " ", ! "has cache expiration: ", $expire_time ); ! return $expire_time; } *************** *** 696,705 **** my $cache = CTX->cache; ! return unless ( $cache ); my $key = $self->_create_cache_key(); ! $cache->set({ key => $key, ! data => $content, ! expire => $expiration }); # Now set the tracking data so we can expire when needed --- 715,730 ---- my $cache = CTX->cache; ! unless ( $cache ) { ! $log->warn( "No cache object returned from content; cannot cache ", ! "content from action" ); ! return; ! } my $key = $self->_create_cache_key(); ! $cache->set({ ! key => $key, ! data => $content, ! expire => $expiration ! }); # Now set the tracking data so we can expire when needed *************** *** 709,715 **** push @{ $tracking->{ $class } }, $key; $log->is_debug && ! $log->debug( "Adding cache key [$key] to class [$class]" ); ! $cache->set({ key => CACHE_CLASS_KEY, ! data => $tracking }); } --- 734,742 ---- push @{ $tracking->{ $class } }, $key; $log->is_debug && ! $log->debug( "Adding tracking cache key '$key' to class '$class'" ); ! $cache->set({ ! key => CACHE_CLASS_KEY, ! data => $tracking ! }); } *************** *** 723,727 **** my $params = $self->cache_param; return [] unless ( ref $params eq 'HASH' ); ! return $params->{ $task }; } --- 750,754 ---- my $params = $self->cache_param; return [] unless ( ref $params eq 'HASH' ); ! return $params->{ $task } || []; } *************** *** 734,737 **** --- 761,766 ---- # will be ignored. + # See 'cache_expire' as well + sub name { my ( $self ) = @_; *************** *** 808,814 **** return $self->{ $prop }; } ! return { map { $_ => $self->{ $_ } } ( keys %PROPS, 'is_secure', 'name' ) }; } # Clear out a property (since passing undef for a set won't work) --- 837,849 ---- return $self->{ $prop }; } ! return { map { $_ => $self->{ $_ } } $self->property_names }; } + # All items in %PROPS plus special properties we handle separately; + # 'cache_expire' is handled in the caching section + + sub property_names { + return ( keys %PROPS, 'is_secure', 'name', 'cache_expire' ); + } # Clear out a property (since passing undef for a set won't work) |