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

When using mpi4py.MPI,

@cache(with_mpi=True)
def sum(a,b):
   return a+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.5.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

pycachera-4.5.1-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

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