Update of /cvs/scoop/scoop/lib/Scoop
In directory lithium.sabren.com:/tmp/cvs-serv3971/lib/Scoop

Modified Files:
	Cache.pm 
Log Message:
Checking in code to use memcached with Scoop instead of the native caching system. -j


Index: Cache.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Cache.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Cache.pm	8 Feb 2006 03:42:02 -0000	1.9
--- Cache.pm	26 Apr 2006 20:56:47 -0000	1.10
***************
*** 82,86 ****
  			NOCACHE => 1
  		});
! 	}
  
  	return $time;
--- 82,86 ----
  			NOCACHE => 1
  		});
! 	 }
  
  	return $time;
***************
*** 100,105 ****
  	warn "[cache] (fetch) Called for resource $resource\n" if $DEBUG;
  
  	# first, check to see if the resource exists in the cache
! 	return unless $self->{cache}->{data}->{$resource};
  	# easy access to this resource
  	my $data = $self->{cache}->{data}->{$resource};
--- 100,116 ----
  	warn "[cache] (fetch) Called for resource $resource\n" if $DEBUG;
  
+ 	# if we're using memcached, short circuit the rest of the function
+ 	if($self->{scoop}->{MEMCACHED} && $resource ne 'boxes'){
+ 		warn "fetching $resource with memcached...\n" if $DEBUG;
+ 		my $S = $self->{scoop}; # and a flip
+ 		# one nice thing, at least, is that the memcached server
+ 		# seems to handle a lot of the stuff that we'd ordinarily
+ 		# need to worry about ourselves, so this is, at least, a lot
+ 		# simpler.
+ 		my $data = $S->memcached->get($resource);
+ 		return $data->{value};
+ 		}
  	# first, check to see if the resource exists in the cache
!         return unless $self->{cache}->{data}->{$resource};
  	# easy access to this resource
  	my $data = $self->{cache}->{data}->{$resource};
***************
*** 162,165 ****
--- 173,202 ----
  	return unless $resource && $value;
  	my $now = time();
+ 	if($self->{scoop}->{MEMCACHED}){
+ 		my $S = $self->{scoop};
+ 		warn "Storing $resource with value $value with memcached\n" if $DEBUG;
+ 		# do we need to fiddle with expires?
+ 		# might as well
+ 		if($expires){
+ 			if ($expires =~ /^\+\d+\w/) {
+                         	my $offset = $self->{scoop}->time_relative_to_seconds($expires);
+                         	$expires = $now + $offset;
+                 	} elsif ($expires =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/) {
+                         	$expires = $self->{scoop}->time_absolute_to_seconds($expires);
+                 	} else {
+                         	warn "[cache] (store) Invalid expires time: $expires";
+                 		}
+ 
+ 			}
+ 		# Looks like we have to force some of this stuff in, so
+ 		# the stamping stuff works right
+ 		my $data = {};
+ 		$data->{expires} = $expires;
+ 		$data->{value} = $value;
+ 		$data->{last_update} = $data->{last_access} = $now;
+ 		$self->stamp($resource) unless $self->refresh_one($resource);
+ 		$S->memcached->set($resource, $data, $expires);
+ 		return 1;
+ 		}
  
  	# if this resource doens't exist previously, create a record for it
***************
*** 214,217 ****
--- 251,262 ----
  	warn "[cache] (remove) Starting for resource $resource\n" if $DEBUG;
  
+ 	# once again...
+ 	if($self->{scoop}->{MEMCACHED}){
+ 		warn "Removing $resource from memcached...\n" if $DEBUG;
+ 		# this is really here for completeness
+ 		$self->{scoop}->{MEMCACHED}->delete($resource);
+ 		delete $self->{refresh}->{$resource}; # for completeness -							      # might even be used
+ 		return 1;
+ 		}
  	return unless $self->{cache}->{data}->{$resource};