Skip to main content

A powerfull python caching tool

Project description

PyCachera

A powerful python decorator to cache functions

Tests PyPI / GitHub CodeQL Docker wakatime Documentation Status

Installation

In command line:

pip install pycachera

Usage

Import the pycachera as:

from pycachera import cache

For caching a function

@cache()
def sum(a,b):
   return a+b

For caching a class attributes.

class Math:
   def __init__(self):
       pass
   
   @cache()
   def sum(a,b):
      return a + b  

For caching to a specific directory.

@cache(cachefolder='/home/user/scratch')
def sum(a,b):
   return a+b

For caching with a specific key

@cache(cachekey='This a custom cache')
def sum(a,b):
   return a+b

For printing the info

@cache(verbose=True)
def sum(a,b):
   return a+b

While debugging your script if you want to ignore the cached values you can recache

@cache(recache=True)
def sum(a,b):
   return a+b

When you use cache with a class attribute, and if you want to consider some attributes of that class for caching,

class Math:
   def __init__(self,c):
       self.c = c
   
   @cache(extrarg=['c'])
   def sum(a,b):
      return a + b  

To cache a class property,

class math:
    def __init__(self,a,b):
        self.a = a
        self.b = b
    
    @property
    @cache(extrarg=['a','b'],verbose=True)
    def add(self):
        return self.a + self.b

API

visit pycachera.readthedocs.io

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

pycachera-4.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

pycachera-4.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pycachera-4.0.0.tar.gz.

File metadata

  • Download URL: pycachera-4.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pycachera-4.0.0.tar.gz
Algorithm Hash digest
SHA256 5a7963e5841ead444a06d67d31d0cccbc6a3aa27446eef2e98f6e9817b0a7338
MD5 7cd47c21a1ce1c1c5eb2d5b4873806dd
BLAKE2b-256 7651ae7c18eeafe535a91d1bc32b1a915921de40ef4df9c713847cf0fec5cf7e

See more details on using hashes here.

File details

Details for the file pycachera-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycachera-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pycachera-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 607bead273e9db638501b55b91dce9bc9f9d347c1443d00a26497c70eb637d37
MD5 f3819c2f3e68020f1c8b5d58f9958057
BLAKE2b-256 e27f51db6a6f78793fb03b791b89cb1ba3e1f597f21027df47ca21ec1f9919dc

See more details on using hashes here.

Supported by

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