so_magic.utils.memoize module¶
Implementation of the object pool
- class so_magic.utils.memoize.ObjectsPool(constructor, build_hash, objects={})[source]¶
Bases:
object
Class of objects that are able to return a reference to an object upon request.
Whenever an object is requested, it is checked whether it exists in the pool. Then if it exists, a reference is returned, otherwise a new object is constructed (given the provided callable) and its reference is returned.
- Parameters
constructor (callable) – able to construct the object given arguments
objects (dict) – the data structure representing the object pool
- get_object(*args, **kwargs)[source]¶
Request an object from the pool.
Get or create an object given the input parameters. Existence in the pool is done using the python-build-in hash function. The input *args and **kwargs serve as input in the hash function to create unique keys with which to “query” the object pool.
- Returns
the reference to the object that corresponds to the input arguments, regardless of whether it was found in the pool or not
- Return type
object