add option to disable db cache
This commit is contained in:
8
mhdb.py
8
mhdb.py
@@ -46,12 +46,14 @@ def get_rank(hub, stars):
|
|||||||
|
|
||||||
|
|
||||||
class MHDB(object):
|
class MHDB(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path, use_cache=True):
|
||||||
self.conn = sqlite3.connect(path)
|
self.conn = sqlite3.connect(path)
|
||||||
self.conn.row_factory = sqlite3.Row
|
self.conn.row_factory = sqlite3.Row
|
||||||
|
self.use_cache = use_cache
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
|
|
||||||
def _get_memoized(self, key, query, *args):
|
def _get_memoized(self, key, query, *args):
|
||||||
|
if self.use_cache:
|
||||||
if key in self.cache:
|
if key in self.cache:
|
||||||
v = self.cache[key].get(args)
|
v = self.cache[key].get(args)
|
||||||
if v is not None:
|
if v is not None:
|
||||||
@@ -59,7 +61,9 @@ class MHDB(object):
|
|||||||
else:
|
else:
|
||||||
self.cache[key] = {}
|
self.cache[key] = {}
|
||||||
cursor = self.conn.execute(query, args)
|
cursor = self.conn.execute(query, args)
|
||||||
v = self.cache[key][args] = cursor.fetchall()
|
v = cursor.fetchall()
|
||||||
|
if self.use_cache:
|
||||||
|
self.cache[key][args] = v
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def get_item_names(self):
|
def get_item_names(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user