From 981f2073cc521942f6d4d2cdd0e370d57376437a Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 20 Nov 2007 01:36:40 +0000 Subject: Make better use of the object cache. svn path=/scripts/rpki/sql.py; revision=1334 --- scripts/rpki/sql.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/rpki/sql.py b/scripts/rpki/sql.py index c1681bd7..20ffe1dd 100644 --- a/scripts/rpki/sql.py +++ b/scripts/rpki/sql.py @@ -68,8 +68,16 @@ class sql_persistant(object): @classmethod def sql_fetch(cls, gctx, id): - """Fetch one object from SQL, based on its primary key.""" - return cls.sql_fetch_where1(gctx, "%s = %s" % (cls.sql_template.index, id)) + """Fetch one object from SQL, based on its primary key. Since in + this one case we know that the primary index is also the cache + key, we check for a cache hit directly in the hope of bypassing the + SQL lookup entirely. + """ + key = (cls, id) + if key in sql_cache: + return sql_cache[key] + else: + return cls.sql_fetch_where1(gctx, "%s = %s" % (cls.sql_template.index, id)) @classmethod def sql_fetch_where1(cls, gctx, where): -- cgit v1.2.3