StepCache#

Base class#

class tango.step_cache.StepCache[source]#

This is a mapping from instances of Step to the results of that step. Generally StepCache implementations are used internally by Workspace implementations.

__contains__(step)[source]#

This is a generic implementation of __contains__. If you are writing your own StepCache, you might want to write a faster one yourself.

Return type

bool

abstract __getitem__(step)[source]#

Returns the results for the given step.

Return type

Any

abstract __len__()[source]#

Returns the number of results saved in this cache.

Return type

int

abstract __setitem__(step, value)[source]#

Writes the results for the given step. Throws an exception if the step is already cached.

Return type

None

default_implementation: Optional[str] = 'memory'#

The default implementation is MemoryStepCache.

Implementations#

class tango.step_caches.LocalStepCache(dir)[source]#

This is a StepCache that stores its results on disk, in the location given in dir.

Every cached step gets a directory under dir with that step’s unique_id. In that directory we store the results themselves in some format according to the step’s FORMAT, and we also write a cache-metadata.json file that stores the CacheMetadata.

The presence of cache-metadata.json signifies that the cache entry is complete and has been written successfully.

Tip

Registered as StepCache under the name “local”.

step_dir(step_or_unique_id)[source]#

Returns the directory that contains the results of the step.

You can use this even for a step that’s not cached yet. In that case it will return the directory where the results will be written.

Return type

Path

class tango.step_caches.MemoryStepCache[source]#

This is a StepCache that stores results in memory. It is little more than a Python dictionary.

Tip

Registered as StepCache under the name “memory”.

Metadata#

class tango.step_cache.CacheMetadata(step, format)[source]#
format: Format#

The format used to serialize the step’s result.

step: str#

The step name.