backward compatible caching options
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.0.8 (2012-09-08 14:50:46) stable
|
Version 2.0.8 (2012-09-08 15:46:21) stable
|
||||||
|
|||||||
+18
-6
@@ -1551,10 +1551,22 @@ class BaseAdapter(ConnectionPool):
|
|||||||
return 'SELECT %s %s FROM %s%s%s;' % \
|
return 'SELECT %s %s FROM %s%s%s;' % \
|
||||||
(sql_s, sql_f, sql_t, sql_w, sql_o)
|
(sql_s, sql_f, sql_t, sql_w, sql_o)
|
||||||
|
|
||||||
|
def _select_aux2(self,sql):
|
||||||
|
self.execute(sql)
|
||||||
|
return self.cursor.fetchall()
|
||||||
|
|
||||||
def _select_aux(self,sql,fields,attributes):
|
def _select_aux(self,sql,fields,attributes):
|
||||||
args_get = attributes.get
|
args_get = attributes.get
|
||||||
self.execute(sql)
|
cache = args_get('cache',None)
|
||||||
rows = self.cursor.fetchall()
|
if not cache:
|
||||||
|
rows = self._select_aux2(sql)
|
||||||
|
else:
|
||||||
|
(cache_model, time_expire) = cache
|
||||||
|
key = self.uri + '/' + sql + '/rows'
|
||||||
|
if len(key)>200: key = hashlib.md5(key).hexdigest()
|
||||||
|
rows = cache_model(key,
|
||||||
|
lambda sql=sql: self._select_aux2(sql),
|
||||||
|
time_expire)
|
||||||
if isinstance(rows,tuple):
|
if isinstance(rows,tuple):
|
||||||
rows = list(rows)
|
rows = list(rows)
|
||||||
limitby = args_get('limitby', None) or (0,)
|
limitby = args_get('limitby', None) or (0,)
|
||||||
@@ -1568,13 +1580,13 @@ class BaseAdapter(ConnectionPool):
|
|||||||
Always returns a Rows object, possibly empty.
|
Always returns a Rows object, possibly empty.
|
||||||
"""
|
"""
|
||||||
sql = self._select(query, fields, attributes)
|
sql = self._select(query, fields, attributes)
|
||||||
if attributes.get('cache', None):
|
cache = attributes.get('cache', None)
|
||||||
args = (sql,fields,attributes)
|
if cache and attributes.get('cacheable',False):
|
||||||
(cache_model, time_expire) = attributes['cache']
|
|
||||||
del attributes['cache']
|
del attributes['cache']
|
||||||
attributes['cacheable'] = True
|
(cache_model, time_expire) = cache
|
||||||
key = self.uri + '/' + sql
|
key = self.uri + '/' + sql
|
||||||
if len(key)>200: key = hashlib.md5(key).hexdigest()
|
if len(key)>200: key = hashlib.md5(key).hexdigest()
|
||||||
|
args = (sql,fields,attributes)
|
||||||
return cache_model(
|
return cache_model(
|
||||||
key,
|
key,
|
||||||
lambda self=self,args=args:self._select_aux(*args),
|
lambda self=self,args=args:self._select_aux(*args),
|
||||||
|
|||||||
Reference in New Issue
Block a user