Skip to main content

a simple tool for making caching functions, methods, and class methods a little bit easier.

Project description

django-cache-helper

  PyPI Test Suite Coverage Status

Overview

django-cache-helper is a simple tool for making caching functions, methods, and class methods a little bit easier. It is largely based off of django-cache-utils, however, since cache-utils did not support caching model methods by instance and carried other features I didn't need, django-cache-helper was created.

In order to cache and invalidate a function/method/class_method/static_method:

Support

Python
3.7, 3.8, 3.9, 3.10

How to Cache

# Caching a function
@cached(60*60)  # 60 Minutes
def foo(bar):
	return bar

class Incrementer:

    @cached_instance_method(60 * 60)
    def instance_increment_by(self, num):
        return num

    @classmethod
    @cached_class_method(60 * 60)
    def class_increment_by(cls, num):
        return num

    @staticmethod
    @cached(60 * 60)
    def get_datetime():
        return datetime.utcnow()

How to invalidate a cache

foo(1)
foo.invalidate(1)

Incrementer.instance_increment_by(1)
Incrementer.instance_increment_by.invalidate(1)

Incrementer.class_increment_by(1)
Incrementer.class_increment_by.invalidate(1)

Incrementer.get_datetime()
Incrementer.get_datetime.invalidate()

How to run tests

  1. Create and activate a new Python virtual environment using the package manager of your choice (e.g., pyenv-virtualenv, virtualenv, etc.).

  2. Install requirements.

    pip install -r requirements.txt
    
  3. Install the django_cache_helper package in editable mode

    pip install -e .
    
  4. Run tests using manage.py:

    cd test_project
    python manage.py test
    

Note that the current test suite generates some expected warnings, which are manually suppressed in the test code.

Contributors ✨

Thanks goes to these wonderful people.

Kevin Fox
Kevin Fox
Tom Jakeway
Tom Jakeway
Ara Anjargolian
Ara Anjargolian
Hyuckin David Lim
Hyuckin David Lim
James
James

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

django_cache_helper-1.0.8.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

django_cache_helper-1.0.8-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file django_cache_helper-1.0.8.tar.gz.

File metadata

  • Download URL: django_cache_helper-1.0.8.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for django_cache_helper-1.0.8.tar.gz
Algorithm Hash digest
SHA256 cf69d635d04e39d6f27eb4db2509c73f05c5490e806e85a89c03bffafaa0ba70
MD5 ac6264db3f7cf5aae728157609f7eb53
BLAKE2b-256 de50ac003161ee23b9354ac3f36fe79cbc6195b51f49abdc14af58fe8a0432d8

See more details on using hashes here.

File details

Details for the file django_cache_helper-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cache_helper-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 95bd413e40bda47af17ce5f0f3473abf95bae8a1d7935ea79309bcb940d25526
MD5 0c83c0f94c671e4aa3fa4e9b43570361
BLAKE2b-256 ed9c7584f59939d9041be9aaee309836ef1961d00c498ed8d332fbf10caeff01

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