[ADD] cache dict on the cursor, for request-local repeated reads
bzr revid: xmo@openerp.com-20120924101404-cel6oy1akabbo7id
This commit is contained in:
parent
a9bc82c46d
commit
b4421c8fba
|
@ -138,6 +138,16 @@ class Cursor(object):
|
||||||
sure you use psycopg2 v2.4.2 or newer if you use PostgreSQL 9.1 and
|
sure you use psycopg2 v2.4.2 or newer if you use PostgreSQL 9.1 and
|
||||||
the performance hit is a concern for you.
|
the performance hit is a concern for you.
|
||||||
|
|
||||||
|
.. attribute:: cache
|
||||||
|
|
||||||
|
Cache dictionary with a "request" (-ish) lifecycle, only lives as
|
||||||
|
long as the cursor itself does and proactively cleared when the
|
||||||
|
cursor is closed.
|
||||||
|
|
||||||
|
This cache should *only* be used to store repeatable reads as it
|
||||||
|
ignores rollbacks and savepoints, it should not be used to store
|
||||||
|
*any* data which may be modified during the life of the cursor.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
IN_MAX = 1000 # decent limit on size of IN queries - guideline = Oracle limit
|
IN_MAX = 1000 # decent limit on size of IN queries - guideline = Oracle limit
|
||||||
|
|
||||||
|
@ -182,6 +192,8 @@ class Cursor(object):
|
||||||
|
|
||||||
self._default_log_exceptions = True
|
self._default_log_exceptions = True
|
||||||
|
|
||||||
|
self.cache = {}
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if not self.__closed and not self._cnx.closed:
|
if not self.__closed and not self._cnx.closed:
|
||||||
# Oops. 'self' has not been closed explicitly.
|
# Oops. 'self' has not been closed explicitly.
|
||||||
|
@ -279,6 +291,8 @@ class Cursor(object):
|
||||||
if not self._obj:
|
if not self._obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
del self.cache
|
||||||
|
|
||||||
if self.sql_log:
|
if self.sql_log:
|
||||||
self.__closer = frame_codeinfo(currentframe(),3)
|
self.__closer = frame_codeinfo(currentframe(),3)
|
||||||
self.print_log()
|
self.print_log()
|
||||||
|
|
Loading…
Reference in New Issue