slipstream.caching

Slipstream caching.

Attributes

Classes

Cache

Create a RocksDB database in the specified folder.

Module Contents

slipstream.caching.MB = 1048576[source]
slipstream.caching.MINUTES = 60[source]
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.ICache

Create 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!'}
name[source]
db[source]
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

set_dumps(dumps: Callable[[Any], bytes]) None[source]

Set custom dumps function.

set_loads(dumps: Callable[[bytes], Any]) None[source]

Set custom loads function.

set_read_options(read_opt: rocksdict.ReadOptions) None[source]

Set custom read options.

set_write_options(write_opt: rocksdict.WriteOptions) None[source]

Set custom write options.

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.

iter(read_opt: rocksdict.ReadOptions | None = None) rocksdict.RdictIter[source]

Get iterable.

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(name: str) rocksdict.Rdict[source]

Get column family by name.

get_column_family_handle(name: str) rocksdict.ColumnFamily[source]

Get column family handle by name.

drop_column_family(name: str) None[source]

Drop column family 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.

snapshot() rocksdict.Snapshot[source]

Create snapshot of current column family.

path() str[source]

Get current database path.

set_options(options: Dict[str, str]) None[source]

Set options for current column family.

property_value(name: str) str | None[source]

Get property by name from current column family.

property_int_value(name: str) int | None[source]

Get property as int by name from current column family.

latest_sequence_number() int[source]

Get sequence number of the most recent transaction.

live_files() List[Dict[str, Any]][source]

Get list of all table files with their level, start/end key.

compact_range(begin: slipstream.interfaces.Key | None, end: slipstream.interfaces.Key | None, compact_opt: rocksdict.CompactOptions = CompactOptions()) None[source]

Run manual compaction on range for the current column family.

close() None[source]

Flush memory to disk, and drop the current column family.

flush(wait: bool = True) None[source]

Manually flush the current column family.

flush_wal(sync: bool = True) None[source]

Manually flush the WAL buffer.

destroy(options: rocksdict.Options = Options()) None[source]

Delete the database.