develooper Front page | perl.beginners | Postings from January 2002

Maintaining a Cache of Hash References

Thread Next
Tomasi, Chuck
January 15, 2002 09:50
Maintaining a Cache of Hash References
Message ID:
I'm trying to maintain a cache of hashes to reduce database hits.  What I
want is to determine if I've retrieved the data from the DB before, if so,
just pass back the copy of information used last time, otherwise read it
from the DB and make a note of it.  It would seem I'm not copying the
information in to the $user arg properly.  Something like this:

@UserCache;	# Place to store data already seen
sub GetUser
	my ($id, $user)=@_;	# record number and hash reference to

	if (defined($UserCache[$id])) {

        $user = $UserCache[$id];                                            

	# Code here to read info from the database and put it in $user as

	# Store the info from the DB for later
	$UserCache[$id] = $user;

	return 1;



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About