Python编程:使用cachy缓存数据
发布日期:2021-07-01 06:08:31
浏览次数:3
分类:技术文章
本文共 796 字,大约阅读时间需要 2 分钟。
cachy使用pickle对对象进行序列化
支持驱动 File,Redis,Memcached,Database文档
https://cachy.readthedocs.io/en/latest/installation.html1、安装
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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月30日 22时47分32秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
内存对齐详解
2019-05-01
秋招总结(一)-C++归纳
2019-05-01
秋招总结(三)-操作系统归纳
2019-05-01
LINUX CP命令详解
2019-05-01
source insight快捷键及使用技巧
2019-05-01
映 射 ALT 键
2019-05-01
vim使用快捷键F4生成文件头注释、F5生成main函数模板、F6生成.h文件框架模板
2019-05-01
OV5620的视频驱动
2019-05-01
C++中两个类交叉定义或递归定义的解决办法
2019-05-01
记一次Hive 行转列 引起的GC overhead limit exceeded
2019-05-01
OpenGL ES八 - 交叉存取顶点数据
2019-05-01
crontab定时任务写法
2019-05-01
nginx: [emerg] unknown directive "if($remote_addr" in /usr/local/tools/nginx/conf/nginx.conf:57
2019-05-01
module pip has no attribute main问题解决
2019-05-01
LeetCode 134.Gas Station (加油站)
2019-05-01
Python之命名元组 (namedtuple)
2019-05-01
使用libpcap过滤arp
2019-05-01
[转帖]Robots.txt指南
2019-05-01
正则表达式简介(微软)--6.优先权顺序
2019-05-01