caching: simplify sqlite code
parent
1ff7e4103c
commit
cbf7b3f77b
|
@ -58,8 +58,8 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
class SQLiteCache(BaseCache):
|
class SQLiteCache(BaseCache):
|
||||||
def __init__(self, filename=':memory:'):
|
def __init__(self, path=':memory:'):
|
||||||
self.con = sqlite3.connect(filename, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False)
|
self.con = sqlite3.connect(path, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False)
|
||||||
|
|
||||||
with self.con:
|
with self.con:
|
||||||
self.con.execute('CREATE TABLE IF NOT EXISTS data (ky UNICODE PRIMARY KEY, data BLOB, timestamp INT)')
|
self.con.execute('CREATE TABLE IF NOT EXISTS data (ky UNICODE PRIMARY KEY, data BLOB, timestamp INT)')
|
||||||
|
@ -168,13 +168,9 @@ if 'CACHE' in os.environ:
|
||||||
)
|
)
|
||||||
|
|
||||||
elif os.environ['CACHE'] == 'sqlite':
|
elif os.environ['CACHE'] == 'sqlite':
|
||||||
if 'SQLITE_PATH' in os.environ:
|
default_cache = SQLiteCache(
|
||||||
path = os.getenv('SQLITE_PATH')
|
os.getenv('SQLITE_PATH', ':memory:')
|
||||||
|
)
|
||||||
else:
|
|
||||||
path = ':memory:'
|
|
||||||
|
|
||||||
default_cache = SQLiteCache(path)
|
|
||||||
|
|
||||||
elif os.environ['CACHE'] == 'redis':
|
elif os.environ['CACHE'] == 'redis':
|
||||||
default_cache = RedisCacheHandler(
|
default_cache = RedisCacheHandler(
|
||||||
|
|
Loading…
Reference in New Issue