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

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.6
File Size Uploaded Provenance Actions
k3cacheable-0.1.6.tar.gz 8.7 kB Without provenance Details for k3cacheable-0.1.6.tar.gz

Built distribution (wheel)

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

Total release size: 15.6 kB

Release files / k3cacheable-0.1.6.tar.gz

Download URL k3cacheable-0.1.6.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d088c940804a25dc04ce88d0a08d4e8815fa559332d1d00aec368fe9808d0936
BLAKE2b-256 checksum
How to use checksums
5cce2137d708c6174b21f9ed7c2d925afa6aed79da376d36438cbecc07cdc872
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.6-py3-none-any.whl

Download URL k3cacheable-0.1.6-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07c80b0354ec35b0385bbb27276c74a360d25f330fc0eea7023520ca382c4a75
BLAKE2b-256 checksum
How to use checksums
0a8cc78ba99a0a195939d3c0776421cb937f8fe24bb1475d2af7001b274a23f3
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.6

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