Skip to main content

No project description provided

Project description

cachemethod

python's missing cache functionality, you can cache a regular function you can cache staticmethod and classmethod but you can't really cache a method that takes self.

pip3 install cachemethod

why can't I use cache on a method that takes self?

python cache doesn't actually stores the hash of the *args and *kwargs (including self), but it puts it into a tuple (which is hashable) and that tuple is used as a key in the cache dict, thus storing the reference to self in that tuple causes the instance to be a live until the cache is cleared or it runs of our space (if you use lru_cache)

why not just hash the items then?

the default hash implementation for classes uses the allocated memory for instances, so if an instance memory gets freed, the cache is not really valid anymore but it is still in the cache dict, so instance that was created on the same memory and passed the same arguments can hit the cache and cause unexpected results

how this package solves the issue

it creates a seed which is a random integer and attaches it to the instance, based on that seed caching is done not relying on the class hash and not storing references

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cachemethod-1.0.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cachemethod-1.0.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file cachemethod-1.0.0.tar.gz.

File metadata

  • Download URL: cachemethod-1.0.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.3-arch1-2

File hashes

Hashes for cachemethod-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5da4f883532ec737d3838779933eb19967e53ccaa2012844783751369b86c65a
MD5 be4bb20a99cb403c5f9ec1887c11472c
BLAKE2b-256 41b672c7093d914e9608dd18a17769f8bc3cdafaa713631dc6d206e154a5ecbc

See more details on using hashes here.

File details

Details for the file cachemethod-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cachemethod-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.3-arch1-2

File hashes

Hashes for cachemethod-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa1caac59184dbd3d9b29fb87ea2f8b50bdcf9f1e8e43d36207ed3b0ff2602c
MD5 c09c160d66c82dfba37dd0ed2009c3df
BLAKE2b-256 2c89240087e484a6f3b0c5645f071f8378d954cd1d80aadf6e88cbb83dda9bb4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page