trimesh.caching module

caching.py

Functions and classes that help with tracking changes in ndarrays and clearing cached values based on those changes.

Classes

Cache(id_function)

Class to cache values which will be stored until the result of an ID function changes.

DataStore()

A class to store multiple numpy arrays and track them all for changes.

TrackedArray

Subclass of numpy.ndarray that provides hash methods to track changes.

Functions

cache_decorator(function)

A decorator for class methods, replaces @property but will store and retrieve function return values in object cache.

tracked_array(array[, dtype])

Properly subclass a numpy ndarray to track changes.

class trimesh.caching.Cache(id_function)

Bases: object

Class to cache values which will be stored until the result of an ID function changes.

Methods

clear([exclude])

Remove all elements in the cache.

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.

clear(exclude=None)

Remove all elements in the cache.

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

Methods

clear()

Remove all data from the DataStore.

crc()

Get a CRC reflecting everything in the DataStore.

fast_hash()

Get a CRC32 or xxhash.xxh64 reflecting the DataStore.

is_empty()

Is the current DataStore empty or not.

md5()

Get an MD5 reflecting everything in the DataStore.

update(values)

Attributes

mutable

Is data allowed to be altered or not.

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

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.

Methods

crc()

A zlib.crc32 or zlib.adler32 checksum of the current data.

fast_hash()

An xxhash.b64 hash of the array.

md5()

Return an MD5 hash of the current array.

Attributes

mutable

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

Return type

int, checksum from zlib.crc32 or zlib.adler32

fast_hash()

An xxhash.b64 hash of the array.

Returns

xx

Return type

int, xxhash.xxh64 hash of array.

md5()

Return an MD5 hash of the current array.

Returns

md5

Return type

str, hexadecimal MD5 of the array

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.

Parameters

function (method) –

This is used as a decorator: ``` @cache_decorator def foo(self, things):

return ‘happy days’

```

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

TrackedArray