Skip to main content

an asyncio cache

Project description

info:

A caching solution for asyncio

https://img.shields.io/pypi/v/async-cache.svg https://www.codetriage.com/iamsinghrajat/async-cache/badges/users.svg https://static.pepy.tech/personalized-badge/async-cache?period=total&units=international_system&left_color=black&right_color=blue&left_text=Downloads async-cache

Installation

pip install async-cache

Basic Usage

# LRU Cache
from cache import AsyncLRU

@AsyncLRU(maxsize=128)
async def func(*args, **kwargs):
    """
    maxsize : max number of results that are cached.
              if  max limit  is reached the oldest result  is deleted.
    """
    pass


# TTL Cache
from cache import AsyncTTL

@AsyncTTL(time_to_live=60, maxsize=1024, skip_args=1)
async def func(*args, **kwargs):
    """
    time_to_live : max time for which a cached result  is valid (in seconds)
    maxsize : max number of results that are cached.
              if  max limit  is reached the oldest result  is deleted.
    skip_args : Use `1` to skip first arg of func in determining cache key
    """
    pass

# Supports primitive as well as non-primitive function parameter.
# Currently TTL & LRU cache is supported.

Advanced Usage

class CustomDataClass:
    id: int
    value: int


from cache import AsyncLRU

@AsyncLRU(maxsize=128)
async def func(model: "CustomDataClass"):
    ...
    # function logic
    ...

# async-cache will work even if function parameters are:
#   1. orm objects
#   2. request object
#   3. any other custom object type.


# To refresh the function result use the `use_cache=False` param in the function invocation
func(*args, use_cache=False, **kwargs)

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

async_cache-1.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

async_cache-1.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file async_cache-1.2.1.tar.gz.

File metadata

  • Download URL: async_cache-1.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for async_cache-1.2.1.tar.gz
Algorithm Hash digest
SHA256 985f29dfa0ce66d9b8bf2071fd9e207a19047b1ce5a980c8c27cdf6d166588d5
MD5 7070ea689ef5b31b6b3deccc675d2a07
BLAKE2b-256 fbb857d264f9a9426558d1b62fb14e3c9a4bedb2afd892d50b6e381d1c36ac85

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_cache-1.2.1.tar.gz:

Publisher: python-publish.yml on iamsinghrajat/async-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_cache-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: async_cache-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for async_cache-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8418c71112e11b5785c5ed99bbae10262b74b3138c39ab18e952a8932557d78
MD5 034724cdfd0be08ea150418572e66d27
BLAKE2b-256 819bb881f188e60adc3a8ff8e21075fecde9eb472a79b72125c7c5d32e10f995

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_cache-1.2.1-py3-none-any.whl:

Publisher: python-publish.yml on iamsinghrajat/async-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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