Skip to main content

k3cacheable

Action-CI Documentation Status Package

Cache data which access frequently.

k3cacheable is a component of pykit3 project: a python3 toolkit set.

Cache data which access frequently.

Install

pip install k3cacheable

Synopsis

import time

import k3cacheable

# create a `LRU`, capacity:10 timeout:60
c = k3cacheable.LRU(10, 60)

# set value like the `dict`
c["key"] = "val"

# get value like the `dict`
# if item timeout, delete it and raise `KeyError`
# if item not exist, raise `KeyError`
try:
    val = c["key"]
except KeyError:
    print("key error")

cache_data = {
    "key1": "val_1",
    "key2": "val_2",
}


# define the function with a decorator
@k3cacheable.cache("cache_name", capacity=100, timeout=60, is_deepcopy=False, mutex_update=False)
def get_data(param):
    return cache_data.get(param, "")


# call `get_data`, if item has not been cached, cache the return value
data = get_data("key1")

# call `get_data` use the same param, data will be got from cache
time.sleep(1)
data = get_data("key1")

# if item timeout, when call `get_data`, cache again
time.sleep(1)
data = get_data("key1")


# define a method with a decorator
class MethodCache:
    @k3cacheable.cache("method_cache_name", capacity=100, timeout=60, is_deepcopy=False, mutex_update=False)
    def get_data(self, param):
        return cache_data.get(param, "")


mm = MethodCache()
data = mm.get_data("key2")

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3cacheable 0.1.5

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

Source distribution (sdist)

Source distribution for k3cacheable 0.1.5
File Size Uploaded Provenance Actions
k3cacheable-0.1.5.tar.gz 7.5 kB Without provenance Details for k3cacheable-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for k3cacheable 0.1.5
File Interpreter ABI Platform Actions
k3cacheable-0.1.5-py3-none-any.whl Python 3 none any Details for k3cacheable-0.1.5-py3-none-any.whl

Total release size: 14.0 kB

Release files / k3cacheable-0.1.5.tar.gz

Download URL k3cacheable-0.1.5.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4b775044a13f719585816a3ad7db36baa0813a4f207523bca6c0cdb98b5faba1
BLAKE2b-256 checksum
How to use checksums
3c410143610926f65b73f7962179ea5931acff6ccbddde8397b72e94b6176363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3cacheable-0.1.5-py3-none-any.whl

Download URL k3cacheable-0.1.5-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d80950db670be3a0a3ab721ae18af1b299ed9721defcdccb9a5319358db1c10
BLAKE2b-256 checksum
How to use checksums
3e707ae793c974dc73ce1a684341e2609ed55abd4bfafc736a05f06f73de0b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for k3cacheable 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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