From: Vsevolod (S. I. <si...@cs...> - 2004-01-07 00:21:30
|
Chris, I have tried to use caching, because otherwise the linked_to attributes are retrieved anew every time, making any kind of change to them non-permanent. However, it does not work. I was only able to get it to work by overriding use_cache() and returning 1 in my SPOPS superclass. Here's what happens: The first time a DB call happens, SPOPS tries to get the data from the global cache. Irregardless of whether it was found or not, skip_cache is incremented: DBI.pm <pre> sub fetch { .. if ( ref $p->{data} eq 'HASH' ) { $obj = $class->new({ %{ $p->{data} }, skip_default_values => 1 }); } else { $obj = $class->get_cached_object({ %{ $p }, id => $id }); $p->{skip_cache}++; # Set so we don't re-cache it later } .. $obj->_fetch_post_process($p, $level); } </pre> Note that the last thing in the fetch() function is a call to _fetch_post_process in SPOPS.pm: <pre> sub _fetch_post_process { my ( $self, $p, $level ) = @_; # Create an entry for this object in the cache unless either the # class or this call to fetch() doesn't want us to. $self->set_cached_object( $p ); </pre> _fetch_post_process calls set_cached_object() in SPOPS.pm. Note that this will fail if use_cache() returns 1; <pre> sub set_cached_object { my ( $self, $p ) = @_; return undef unless ( ref $self ); return undef unless ( $self->id ); return undef unless ( $self->use_cache( $p ) ); return $self->global_cache->set({ data => $self }); } </pre> Finally, use_cache() is: <pre> sub use_cache { return undef unless ( $USE_CACHE ); my ( $class, $p ) = @_; return undef if ( $p->{skip_cache} ); return undef if ( $class->no_cache ); return undef unless ( $class->global_cache ); return 1; } </pre> We check $p->{skip_cache}, which was set to 1 after an unsuccessful call to get(), return undef from use_cache()... and never call cache::set()! I think the fix is simple - you should increment skip_cache after get() in fetch() only if ( ref $obj eq $class ) You use the same check literally one line below in determining whether or not to access the database. Simon -- Simon (Vsevolod ILyushchenko) si...@cs... http://www.simonf.com America's business leaders simply don't want to think about complex technology issues - they want to think about golf. Microsoft promises them that. Andrew Grygus, www.aaxnet.com |