relstorage.cache.storage_cache

class StorageCache(adapter, options, prefix, _parent=None)[source]

Bases: relstorage._mvcc.DetachableMVCCDatabaseViewer

RelStorage integration with memcached or similar.

Holds a list of memcache clients in order from most local to most global. The first is a LocalClient, which stores the cache in the Python process, but shares the cache between threads.

MVCCInternalConsistencyError

alias of AssertionError

after_tpc_finish(tid, temp_storage)[source]

Flush queued changes.

This is called after the database commit lock is released, but before control is returned to the Connection.

Now that this tid is known, send all queued objects to the cache. The cache will have (oid, tid) entry for each object we have been holding on to (well, in a big transaction, some of them might actually not get stored in the cache. But we try!)

clear(load_persistent=True)[source]

Remove all data from the cache, both locally (and shared among other instances), and globally.

Called by speed tests.

Starting from the introduction of persistent cache files, this also results in the local client being repopulated with the current set of persistent data. The load_persistent keyword can be used to control this.

Changed in version 2.0b6: Added the load_persistent keyword. This argument is provisional.

close(**save_args)[source]

Release resources held by this instance, and save any persistent data necessary.

This is only called on the root. If there are still instances that haven’t been released, they’ll be broken.

load(cursor, oid_int)[source]

Load the given object from cache if possible.

Fall back to loading from the database.

Returns (state_bytes, tid_int).

loadSerial(oid_int, tid_int)[source]

Return the locally cached state for the object oid_int as-of exactly tid_int.

If that state is not available in the local cache, return nothing.

This is independent of the current transaction and polling state, and may return data from the future.

If the storage hasn’t polled invalidations, or if there are other viewers open at transactions in the past, it may also return data from the past that has been overwritten (in history-free storages).

new_instance(before=None, adapter=None)[source]

Return a copy of this instance sharing the same local client and having the most current view of the database as collected by any instance.

If before is given, the new cache will use a distinct MVCCDatabaseCoordinator so that its usage pattern does not interfere.

release()[source]

Release resources held by this instance.

This does not corrupt shared state, and must be called on each instance that’s not the root.

This is usually memcache connections if they’re in use.

remove_all_cached_data_for_oids(oids)[source]

Invalidate all cached data for the given OIDs.

This isn’t transactional or locked so it may still result in this or others seeing invalid (ha!) states.

This is a specialized API. It allows violation of our internal consistency constraints. It should only be used when the database is being manipulated at a low level, such as during pack or undo.

remove_cached_data(oid_int, tid_int)[source]

See notes in invalidate_all.

save(**save_args)[source]

Store any persistent client data.

stats()[source]

Return stats. This is a debugging aid only. The format is undefined and intended for human inspection only.

zap_all()[source]

Remove all data from the cache, both locally (and shared among other instances, and globally); in addition, remove any persistent cache files on disk.