Skip to main content

A python decorator for caching the results of functions

Project description

Cache Function Result

Description

这是一个Python包,它提供了一个装饰器用于缓存函数的返回结果。缓存的结果可以指定任意位置,非常的自由,缓存的键则是根据函数名、源代码和参数来控制的。你可以选择排除某些元素,例如函数名、源代码、参数或者关键字参数。

This is a Python package that provides a decorator for caching the results of functions. The cache is stored in a specified directory, and the cache key is generated based on the function name, source code, and arguments. The decorator allows you to exclude certain elements from the cache key, such as the function name, source code, arguments, or keyword arguments.

Installation

You can install this package using pip:

pip install cache_result

features

  • 可以指定缓存的位置
  • 可以自定义缓存的key,例如函数名、源代码、参数或者关键字参数
  • 可以根据参数的名称指定不同的缓存文件夹

Usage

Here is an example of how to use the cache decorator:

from cache_result import cache

@cache('./cache/缓存/自己随便指定一些路径/方便自己区分/时间可以控制版本/20230713/add', exclude=['func_name'], is_print=True)
def add(a, b):
    # Your expensive function implementation here
    print("add", a, b)

    return a + b

print(add(1, 2))
print(add(1, 2))

License

This project is licensed under the MIT License.

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

cache-result-0.1.4.tar.gz (3.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page