summaryrefslogtreecommitdiff
path: root/requests_cache/backends/sqlite.py
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-03-24 16:02:48 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-03-24 16:10:42 -0500
commited7aac51b44d69bd8d1c5d8bc2272d6b89976a87 (patch)
tree638be2ecb62e706514ebd9a2b059cdb8f87f53ff /requests_cache/backends/sqlite.py
parentc4fd835c935c699ee8e4950afc59bafca6b10f69 (diff)
downloadrequests-cache-ed7aac51b44d69bd8d1c5d8bc2272d6b89976a87.tar.gz
Pass along optional kwargs to all storage classes, and make default table names consistent across backends (`'http_cache'`)
Diffstat (limited to 'requests_cache/backends/sqlite.py')
-rw-r--r--requests_cache/backends/sqlite.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/requests_cache/backends/sqlite.py b/requests_cache/backends/sqlite.py
index 43a7588..ac06ec3 100644
--- a/requests_cache/backends/sqlite.py
+++ b/requests_cache/backends/sqlite.py
@@ -1,6 +1,7 @@
import sqlite3
import threading
from contextlib import contextmanager
+from os.path import expanduser
from .base import BaseCache, BaseStorage
@@ -8,20 +9,20 @@ from .base import BaseCache, BaseStorage
class DbCache(BaseCache):
"""SQLite cache backend.
- Reading is fast, saving is a bit slower. It can store big amount of data
- with low memory usage.
+ Reading is fast, saving is a bit slower. It can store big amount of data with low memory usage.
+
+ Args:
+ location: database filename prefix
+ extension: Database file extension
+ fast_save: Speedup cache saving up to 50 times but with possibility of data loss.
+ See :ref:`backends.DbDict <backends_dbdict>` for more info
"""
- def __init__(self, location='cache', fast_save=False, extension='.sqlite', **options):
- """
- :param location: database filename prefix (default: ``'cache'``)
- :param fast_save: Speedup cache saving up to 50 times but with possibility of data loss.
- See :ref:`backends.DbDict <backends_dbdict>` for more info
- :param extension: extension for filename (default: ``'.sqlite'``)
- """
- super().__init__(**options)
- self.responses = DbPickleDict(str(location) + extension, 'responses', fast_save=fast_save)
- self.redirects = DbDict(location + extension, 'redirects')
+ def __init__(self, location='http_cache', extension='.sqlite', fast_save=False, **kwargs):
+ super().__init__(**kwargs)
+ db_path = expanduser(str(location) + extension)
+ self.responses = DbPickleDict(db_path, table_name='responses', fast_save=fast_save, **kwargs)
+ self.redirects = DbDict(db_path, table_name='redirects', **kwargs)
class DbDict(BaseStorage):
@@ -38,7 +39,7 @@ class DbDict(BaseStorage):
correspondent tables: ``table1``, ``table2`` and ``table3``
"""
- def __init__(self, filename, table_name='data', fast_save=False, **kwargs):
+ def __init__(self, filename, table_name='http_cache', fast_save=False, **kwargs):
"""
:param filename: filename for database (without extension)
:param table_name: table name