endas.arraycache.ArrayCache

class endas.arraycache.ArrayCache

Bases: object

Trivial large data cache implementation.

Large data cache is used in situations where keeping all data in memory is likely not going to be feasible. Therefore, some data may be persisted to other storage (e.g. disk) for later retrieval.

Note

This implementation is basic and simply stores all data in memory via a Python dictionary. Also, it is not thread safe. Use one of subclasses for more suitable behaviour or implement your own.

put(data)

Places an object into the cache and returns handle for retrieval. The data is always copied.

Parameters:data – Data instance to store.

Returns : Handle object that represents the stored array.

get(handle, force_copy=False)

Retrieves data from the cache.

Parameters:handle – Handle to the data instance to retrieve.

Returns : Original data object.

get_exclusive(handle)

Retrieves data from the cache with exclusive and writable access.

Parameters:handle – Handle to the data instance to retrieve.

Returns : Original data object.

release(handle)

Releases exclusive access to object pointed by given handle. Only handles obtained by the get_exclusive() method should be released.

Parameters:handle – Handle to the data instance to retrieve.

Returns : None

remove(handle)

Removes data from the cache.

Parameters:arrayhandle – Handle to the data instance to remove.

Returns: None

clear()

Removes all data form the cache. This also invalidates all previously returned handles.