sqlite¶
Summary¶
|
|
|
An async interface for caching objects in a SQLite database. |
|
Same as |
|
Template function to get an accurate function signature for |
Module Contents¶
- class SQLiteBackend(cache_name='aiohttp-cache', use_temp=False, fast_save=False, autoclose=True, **kwargs)¶
Bases:
CacheBackend
Async cache backend for SQLite
Notes
Requires aiosqlite
Accepts keyword arguments for
sqlite3.connect()
/aiosqlite.connect()
The path to the database file will be
<cache_name>
(or<cache_name>.sqlite
if no file extension is specified)
- Parameters:
cache_name (
str
) – Database filenameuse_temp (
bool
) – Store database in a temp directory (e.g.,/tmp/http_cache.sqlite
). Note: ifcache_name
is an absolute path, this option will be ignored.fast_save (
bool
) – Increase cache write performance, but with the possibility of data loss. See pragma: synchronous for details.autoclose (
bool
) – Close any active backend connections when the session is closedkwargs (
Any
) – Additional keyword arguments forCacheBackend
or backend connection
- class SQLiteCache(filename, table_name='aiohttp-cache', use_temp=False, fast_save=False, **kwargs)¶
Bases:
BaseCache
An async interface for caching objects in a SQLite database.
Example
>>> # Store data in two tables under the 'testdb' database >>> d1 = SQLiteCache('testdb', 'table1') >>> d2 = SQLiteCache('testdb', 'table2')
- Parameters:
filename (
str
) – Database filenametable_name (
str
) – Table nameuse_temp (
bool
) – Store database in a temp directory (e.g.,/tmp/http_cache.sqlite
). Note: ifcache_name
is an absolute path, this option will be ignored.kwargs (
Any
) – Additional keyword arguments forsqlite3.connect()
fast_save (
bool
)
- bulk_commit()¶
Contextmanager to more efficiently write a large number of records at once
Example
>>> cache = SQLiteCache('test') >>> async with cache.bulk_commit(): ... for i in range(1000): ... await cache.write(f'key_{i}', str(i))
- async bulk_delete(keys)¶
Delete item(s) from the cache. Does not raise an error if the item is missing.
- Parameters:
keys (
set
)
- async clear()¶
Delete all items from the cache
- async close()¶
Close any open connections
- async delete(key)¶
Delete an item from the cache. Does not raise an error if the item is missing.
- Parameters:
key (
str
)
- async keys()¶
Get all keys stored in the cache
- Return type:
- async read(key)¶
Read an item from the cache. Returns
None
if the item is missing.
- async values()¶
Get all values stored in the cache
- Return type:
- async write(key, item)¶
Write an item to the cache
- Parameters:
key (
str
)item (
Union
[CachedResponse
,bytes
,str
,None
,memoryview
])
- class SQLitePickleCache(filename, table_name='aiohttp-cache', use_temp=False, fast_save=False, **kwargs)¶
Bases:
SQLiteCache
Same as
SqliteCache
, but pickles values before saving- async read(key)¶
Read an item from the cache. Returns
None
if the item is missing.
- async values()¶
Get all values stored in the cache
- Return type:
- async write(key, item)¶
Write an item to the cache
- sqlite_template(timeout=5.0, detect_types=0, isolation_level=None, check_same_thread=True, factory=None, cached_statements=100, uri=False)¶
Template function to get an accurate function signature for
sqlite3.connect()