Yes, that's what I want...
 
Returning 1 says "I found data".  If it is found in the cache, always return
1.  If it doesn't find it in the cache, it goes on to query the database
where it returns the number of rows found.
 
--Chuck

-----Original Message-----
From: Wilson, Doug [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 15, 2002 3:47 PM
To: 'Tomasi, Chuck'; '[EMAIL PROTECTED]'
Subject: RE: Maintaining a Cache of Hash References




> From: Tomasi, Chuck [ mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ] 
> 
> @UserCache;   # Place to store data already seen 

This is an array, not a hash, depending on your range of 
id numbers, you might want: 
my %UserCache; # BTW, Are you using 'strict'?? 

> sub GetUser 
> { 
>       my ($id, $user)=@_;     # record number and hash reference to 
> populate 
>       # Store the info from the DB for later 
>       $UserCache[$id] = $user; 
> 
>       return 1; 
You're always returning 1?? Is this useful?? 
You don't want to return something like: 

my $sth = $dbh->prepare_cached("select user from users where id = ?"); 
return scalar($UserCache{$id} ||= $dbh->selectrow_array($sth, undef, $id)); 

> } 


HTH, 
Douglas Wilson 

Reply via email to