trimesh.caching
caching.py
Functions and classes that help with tracking changes in ndarrays and clearing cached values based on those changes.
- class trimesh.caching.Cache(id_function, force_immutable=False)
Bases:
object
Class to cache values which will be stored until the result of an ID function changes.
- __init__(id_function, force_immutable=False)
Create a cache object.
- Parameters
id_function (function) – Returns hashable value
force_immutable (bool) – If set will make all numpy arrays read-only
- clear(exclude=None)
Remove elements in the cache.
- Parameters
exclude (list) – List of keys in cache to not clear.
- delete(key)
Remove a key from the cache.
- id_set()
Set the current ID to the value of the ID function.
- update(items)
Update the cache with a set of key, value pairs without checking id_function.
- verify()
Verify that the cached values are still for the same value of id_function and delete all stored items if the value of id_function has changed.
- class trimesh.caching.DataStore
Bases:
collections.abc.Mapping
A class to store multiple numpy arrays and track them all for changes.
Operates like a dict that only stores numpy.ndarray
- __init__()
- clear()
Remove all data from the DataStore.
- crc()
Get a CRC reflecting everything in the DataStore.
- Returns
crc – CRC of data
- Return type
int
- fast_hash()
Get a CRC32 or xxhash.xxh64 reflecting the DataStore.
- Returns
hashed – Checksum of data
- Return type
int
- is_empty()
Is the current DataStore empty or not.
- Returns
empty – False if there are items in the DataStore
- Return type
bool
- md5()
Get an MD5 reflecting everything in the DataStore.
- Returns
md5 – MD5 of data in hexadecimal
- Return type
str
- property mutable
Is data allowed to be altered or not.
- Returns
is_mutable – Can data be altered in the DataStore
- Return type
bool
- pop(key)
- update(values)
- class trimesh.caching.TrackedArray
Bases:
numpy.ndarray
Subclass of numpy.ndarray that provides hash methods to track changes.
General method is to aggressively set ‘modified’ flags on operations which might (but don’t necessarily) alter the array, ideally we sometimes compute hashes when we don’t need to, but we don’t return wrong hashes ever.
We store boolean modified flag for each hash type to make checks fast even for queries of different hashes.
- md5 : str, hexadecimal MD5 of array
- crc : int, zlib crc32/adler32 checksum
- fast_hash : int, CRC or xxhash.xx64
- crc()
A zlib.crc32 or zlib.adler32 checksum of the current data.
- Returns
crc – Checksum from zlib.crc32 or zlib.adler32
- Return type
int
- fast_hash()
An xxhash.b64 hash of the array.
- Returns
xx – xxhash.xxh64 hash of array.
- Return type
int
- md5()
Return an MD5 hash of the current array.
- Returns
md5 – Hexadecimal MD5 of the array
- Return type
str
- property mutable
- trimesh.caching.cache_decorator(function)
A decorator for class methods, replaces @property but will store and retrieve function return values in object cache.
- trimesh.caching.tracked_array(array, dtype=None)
Properly subclass a numpy ndarray to track changes.
Avoids some pitfalls of subclassing by forcing contiguous arrays and does a view into a TrackedArray.
- Parameters
array (array- like object) – To be turned into a TrackedArray
dtype (np.dtype) – Which dtype to use for the array
- Returns
tracked – Contains input array data
- Return type