""" 
	Class used for caching entries.
	
"""

__version__ = "$Revision: 1.3 $"
# $Source: /home/vladap/src/mysqlUserFolder/RCS/cache.py,v $
#
# $Author: vladap $
# $Date: 2004/05/15 18:25:16 $

import time

# --------------------------------------------------------------------- */

class v_entry:
	
	def __init__ (Self, id, object):
		Self.id = id
		Self.object = object
		
		Self.created = time.time ()
		
	def age (Self):
		return time.time () - Self.created 
		
	def getObj (Self):
		return Self.object
		
	def getId (Self):
		return Self.id

class v_cache:
	
	def __init__ (Self, entry_life):
		Self.life = entry_life
		Self.objects = {}
		
	def add (Self, id, object):
		o = v_entry (id, object)
		Self.objects [id] = o
		
	def get (Self, id):
		o = Self.objects.get (id, None)
		
		if not (o is None):
			if o.age () > Self.life:
				del Self.objects [id]
				o = None
			else:
				o = o.getObj ()
				
		return o
		
	def delete (Self, id):
		if Self.objects.has_key (id):
			del Self.objects [id]
		
		
	