Skip to main content

utic-cache

A caching solution for asyncio. Heavily changed fork of async-cache package.

Installation

pip install utic-cache

Basic Usage

# LRU Cache
from cache import Cached, LRU


@Cached(LRU(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 Cached, TTL


@Cached(TTL(ttl=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

from cache import Cached, LRU


class CustomDataClass:
    id: int
    value: int


@Cached(LRU(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)

Metadata

Release files for utic-cache 2.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for utic-cache 2.2.2
File Size Uploaded
utic_cache-2.2.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for utic-cache 2.2.2
File Interpreter ABI Platform
utic_cache-2.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / utic_cache-2.2.2.tar.gz

Download URL utic_cache-2.2.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
252dfbd9a422fcb6002cc2610d2513397d5e879e40bacfed63ce3e5de59786b0
BLAKE2b-256 checksum
How to use checksums
183b4c32d2acfa77836d9bfa4f06c4bbf7908a550de8fbce9290a4322d997fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.5 Windows/10

Release files / utic_cache-2.2.2-py3-none-any.whl

Download URL utic_cache-2.2.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8513017121912b4c42a721493a659551b49a096771d5d2eaabcb4189e48d46a
BLAKE2b-256 checksum
How to use checksums
1c914b19cb8235d7b1f09681f54febee980a64799f31ef369a329e5640f40c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.5 Windows/10

Release history Release notifications | RSS feed

This release

2.2.2 This release

2 release files

2.2.1

2 release files

2.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page