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.3

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.3
File Size Uploaded Provenance Actions
k3cacheable-0.1.3.tar.gz 7.3 kB Without provenance Details for k3cacheable-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 13.7 kB

Release files / k3cacheable-0.1.3.tar.gz

Download URL k3cacheable-0.1.3.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d7cb4f9869fa6d6f8d136f4b5c2ed5896b51bcc7d58f7696d80dfd5f4a0235d8
BLAKE2b-256 checksum
How to use checksums
b5c7bf0bd5e73011ec27705d8fcffdf20b264862cd90dc9c280da6040e37d07a
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.3-py3-none-any.whl

Download URL k3cacheable-0.1.3-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30b34aa57a0e7db0b5ce9aed1971320caa1e15c7256263b62d670250400758c8
BLAKE2b-256 checksum
How to use checksums
e1488c3249f35bcee446296a1e4e17b31563889886f00c0cb7db5b6a850c7aca
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.3

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