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.5.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycachera-4.5.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.2

File hashes

Hashes for pycachera-4.5.0.tar.gz
Algorithm Hash digest
SHA256 6de8c4aa53985461d67e7d820127e902247e5ef30755468777348675fe99d864
MD5 54d6179f87676beedba5511f4e1816aa
BLAKE2b-256 88c8394833264c1884f815a2461b6299a753c84ad0cee49afebb3392e981bf0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycachera-4.5.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.2

File hashes

Hashes for pycachera-4.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bba2b5fa3ffa0968c1cfbb8d071ab884c293b0c7fa902323866fd92ebc9ac142
MD5 e46a1513885fd14d5aea5d7767775157
BLAKE2b-256 6e4567274899e5c5fbe6410c57bcab5f16d42243f9159a2da3f61abe9be42d5a

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