slipstream.caching¶
Slipstream caching.
Attributes¶
Classes¶
Create a RocksDB database in the specified folder. |
Module Contents¶
- class slipstream.caching.Cache(path: str, options: rocksdict.Options | None = None, column_families: Dict[str, rocksdict.Options] | None = None, access_type: rocksdict.AccessType = AccessType.read_write(), target_table_size: int = 25 * MB, number_of_locks: int = 16)[source]¶
Bases:
slipstream.interfaces.ICacheCreate a RocksDB database in the specified folder.
>>> cache = Cache('db/mycache')
The cache instance acts as a callable to store data:
>>> cache('key', {'msg': 'Hello World!'}) >>> cache['key'] {'msg': 'Hello World!'}
- async transaction(key: slipstream.interfaces.Key)[source]¶
Lock the db entry while using the context manager.
>>> async with cache.transaction('fish'): ... cache['fish'] = '🐟'
This works for asynchronous code (not multi-threading/processing)
While locked, other transactions on the same key will block
Actions outside of transaction blocks ignore ongoing transactions
Reads aren’t limited by ongoing transactions
- get(key: slipstream.interfaces.Key | list[slipstream.interfaces.Key], default: T = None, read_opt: rocksdict.ReadOptions | None = None) Any | T[source]¶
Get item from database by key.
- put(key: slipstream.interfaces.Key, value: Any, write_opt: rocksdict.WriteOptions | None = None) None[source]¶
Put item in database using key.
- delete(key: slipstream.interfaces.Key, write_opt: rocksdict.WriteOptions | None = None) None[source]¶
Delete item from database.
- key_may_exist(key: slipstream.interfaces.Key, fetch: bool = False, read_opt: rocksdict.ReadOptions | None = None) bool | Tuple[bool, Any][source]¶
Check if a key exist without performing IO operations.
- items(backwards: bool = False, from_key: str | int | float | bytes | bool | None = None, read_opt: rocksdict.ReadOptions | None = None) rocksdict.rocksdict.RdictItems[source]¶
Get tuples of key-value pairs.
- keys(backwards: bool = False, from_key: str | int | float | bytes | bool | None = None, read_opt: rocksdict.ReadOptions | None = None) rocksdict.rocksdict.RdictKeys[source]¶
Get keys.
- values(backwards: bool = False, from_key: slipstream.interfaces.Key | None = None, read_opt: rocksdict.ReadOptions | None = None) rocksdict.rocksdict.RdictValues[source]¶
Get values.
- ingest_external_file(paths: List[str], opts: rocksdict.IngestExternalFileOptions = IngestExternalFileOptions()) None[source]¶
Load list of SST files into current column family.
- get_column_family_handle(name: str) rocksdict.ColumnFamily[source]¶
Get column family handle by name.
- create_column_family(name: str, options: rocksdict.Options = Options()) rocksdict.Rdict[source]¶
Craete column family.
- delete_range(begin: slipstream.interfaces.Key, end: slipstream.interfaces.Key, write_opt: rocksdict.WriteOptions | None = None) None[source]¶
Delete database items, excluding end.
- property_int_value(name: str) int | None[source]¶
Get property as int by name from current column family.
- live_files() List[Dict[str, Any]][source]¶
Get list of all table files with their level, start/end key.