cvs commit: p5ee/App-Repository/lib/App/SessionObject RepositoryObjectDomain.pm RepositoryObjectSet.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/03/28 12:32:23

  Modified:    App-Repository/lib/App/SessionObject
                        RepositoryObjectDomain.pm RepositoryObjectSet.pm
  Log:
  _clear_cache() and {max_age}
  
  Revision  Changes    Path
  1.2       +32 -1     p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectDomain.pm
  
  Index: RepositoryObjectDomain.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectDomain.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RepositoryObjectDomain.pm	14 Mar 2005 20:05:05 -0000	1.1
  +++ RepositoryObjectDomain.pm	28 Mar 2005 20:32:22 -0000	1.2
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: RepositoryObjectDomain.pm,v 1.1 2005/03/14 20:05:05 spadkins Exp $
  +## $Id: RepositoryObjectDomain.pm,v 1.2 2005/03/28 20:32:22 spadkins Exp $
   #############################################################################
   
   package App::SessionObject::RepositoryObjectDomain;
  @@ -39,6 +39,34 @@
   # Support Routines
   ###########################################################################
   
  +sub _clear_cache {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $table) = @_;
  +    my (@tables);
  +    if ($table) {
  +        @tables = ($table);
  +    }
  +    else {
  +        my $object_set = $self->{object_set};
  +        if (ref($object_set) eq "HASH") {
  +            foreach my $table (keys %$object_set) {
  +                if ($object_set->{$table}{gotten}) {
  +                    delete $object_set->{$table}{gotten};)
  +                    push(@tables, $table);
  +                }
  +            }
  +        }
  +    }
  +    my $context = $self->{context};
  +    my ($object_set_name, $object_set);
  +    foreach my $table (@tables) {
  +        $object_set_name = $self->{object_set}{$table}{name} || "$self->{name}.$table";
  +        $object_set = $context->session_object($object_set_name);
  +        $object_set->_clear_cache();
  +    }
  +    &App::sub_exit() if ($App::trace);
  +}
  +
   sub set_params {
       &App::sub_entry if ($App::trace);
       my ($self, $params) = @_;
  @@ -52,6 +80,7 @@
       my ($self, $table) = @_;
       my $context = $self->{context};
       my $params = $self->{params} || {};
  +
       my $object_set_name = $self->{object_set}{$table}{name} || "$self->{name}.$table";
       my $args = $self->{object_set}{$table}{args} || {};
       if (!$args->{class}) {
  @@ -64,6 +93,8 @@
           $args->{params} = $params;
       }
       my $object_set = $context->session_object($object_set_name, %$args);
  +    $self->{object_set}{$table}{gotten} = 1;
  +
       $object_set->update_params($params);
       &App::sub_exit($object_set) if ($App::trace);
       return($object_set);
  
  
  
  1.2       +17 -1     p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm
  
  Index: RepositoryObjectSet.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RepositoryObjectSet.pm	14 Mar 2005 20:05:05 -0000	1.1
  +++ RepositoryObjectSet.pm	28 Mar 2005 20:32:22 -0000	1.2
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: RepositoryObjectSet.pm,v 1.1 2005/03/14 20:05:05 spadkins Exp $
  +## $Id: RepositoryObjectSet.pm,v 1.2 2005/03/28 20:32:22 spadkins Exp $
   #############################################################################
   
   package App::SessionObject::RepositoryObjectSet;
  @@ -56,6 +56,13 @@
       &App::sub_exit() if ($App::trace);
   }
   
  +sub set_max_age {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $max_age) = @_;
  +    $self->{max_age} = $max_age;
  +    &App::sub_exit() if ($App::trace);
  +}
  +
   sub set_table {
       &App::sub_entry if ($App::trace);
       my ($self, $table, $repository) = @_;
  @@ -96,6 +103,14 @@
   sub _get_all_objects {
       &App::sub_entry if ($App::trace);
       my ($self) = @_;
  +    if (defined $self->{max_age}) {
  +        my $max_age = $self->{max_age};
  +        my $max_age_time = $self->{max_age_time};
  +        my $time = time();
  +        if (defined $max_age_time && $max_age_time <= $time - $max_age) {
  +            $self->_clear_cache();
  +        }
  +    }
       my $objects = $self->{objects};
       if (!$objects) {
           my $context = $self->{context};
  @@ -105,6 +120,7 @@
           my $params  = $self->{params} || {};
           $objects = $rep->get_objects($table, $params);
           $self->{objects} = $objects;
  +        $self->{max_age_time} = time();
       }
       &App::sub_exit($objects) if ($App::trace);
       return($objects);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.