Python编程:使用cachy缓存数据
发布日期:2021-07-01 06:08:31 浏览次数:2 分类:技术文章

本文共 796 字,大约阅读时间需要 2 分钟。

cachy使用pickle对对象进行序列化

支持驱动 File,Redis,Memcached,Database

文档

https://cachy.readthedocs.io/en/latest/installation.html

1、安装

pip install cachy

2、配置

from cachy import CacheManagerstores = {
'default': 'file', 'stores': {
'file': {
'driver': 'file', 'path': 'cache' } }}cache = CacheManager(stores)

3、CURD

# 添加cache.put('key', 'value', 10)# 获取value = cache.get('key')# print(value)# 检查存在print(cache.has('key'))# cache.increment('key', 1) 报错# 获取并且删除value = cache.pull('key')# 不存在则添加cache.add('key', 'value', 10)# 永久cache.forever('key', 'value')# 移除cache.forget('key')# 获取或更新 remember_forever 永久value = cache.remember('key', 10, 'value')print(value)

4、使用装饰器

默认60 minutes

@cachedef get_users():    print("查询数据库")    return "查询结果"print(get_users())

转载地址:https://pengshiyu.blog.csdn.net/article/details/103505050 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Python:orator-orm操作实践
下一篇:Python/Java/PHP/JS三目运算表达式

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月17日 22时02分37秒