python-memoization icon indicating copy to clipboard operation
python-memoization copied to clipboard

[feature] item_size function

Open FreakTheMighty opened this issue 4 years ago • 0 comments

Overview

When determining how large the cache using max_size is it may be useful to treat some items as larger than other to provide a better proxy for their memory footprint. For example, I have a function that caches 3D meshes. Setting a max_size to a fixed number doesn't capture the fact that some 3D meshes are very large while others are very small.

Proposal

Similar to the custom_key_maker, a developer could provide an item_size function that returns an integer allowing them to calculate the size of cached items based on the cache entry. In the use-case described above, I might return a value based on the number of vertexes in my mesh.

FreakTheMighty avatar Feb 24 '21 17:02 FreakTheMighty