Python轻量级低代码缓存框架
Project description
zdppy_cache
Python的缓存库
使用教程
基本用法
import zdppy_cache as c
# 设置缓存
key = "code"
value = "A13k"
c.set(key, value)
# 获取缓存
print(c.get(key))
# 删除缓存
c.delete(key)
print(c.get(key))
# 清空缓存
c.delete_all()
查询所有的key
默认参数是False,查询所有未过期的。传True则查询所有,包括已过期的。
import zdppy_cache as c
import time
# 设置缓存
key = "code"
value = "A13k"
c.set(key, value, 3)
# 获取所有的缓存的key
print(c.get_all_keys())
time.sleep(3)
print("默认查询未过期的:", c.get_all_keys())
print("查询过期的:", c.get_all_keys(False))
# 清空缓存
c.delete_all()
查询所有的键值对
import zdppy_cache as c
import time
# 设置缓存
key = "code"
value = "A13k"
c.set(key, value, 3)
# 获取所有的缓存的key-value
print(c.get_all_items())
time.sleep(3)
print("默认查询未过期的:", c.get_all_items())
print("查询过期的:", c.get_all_items(False))
# 清空缓存
c.delete_all()
查询所有的有效具体数据
会返回具体详细的缓存信息。
import zdppy_cache as c
import time
# 设置缓存
key = "code"
value = "A13k"
c.set(key, value, 3)
# 获取所有的缓存的key-value
print(c.get_all())
time.sleep(3)
print("默认查询未过期的:", c.get_all())
print("查询过期的:", c.get_all(False))
# 清空缓存
c.delete_all()
获取缓存文件大小
import zdppy_cache as c
import time
# 设置缓存
key = "code"
value = "A13k"
c.set(key, value, 3)
# 获取占据磁盘大小
print(c.get_size())
# 加很多东西
for i in range(100):
c.set(f"zhangsan{i}", i)
print(c.get_size())
# 清空缓存
c.delete_all()
通过账号密码区分用户的缓存
import zdppy_cache
# 设置缓存
key = "code"
value = "A13k"
# 设置缓存
c = zdppy_cache.UserCache("admin", "admin123456")
c.set(key, value, 3)
# 获取缓存
print(c.get(key))
# 让另一个用户去获取缓存
c = zdppy_cache.UserCache("admin", "admin123457")
print("另一个用户", c.get(key))
# 清空缓存
c.delete_all()
基于zdppy_api实现的接口级别的缓存
import api
import zdppy_cache
key1 = "admin"
key2 = "admin123456"
app = api.Api(
routes=[
*zdppy_cache.zdppy_api.cache(key1, key2, api)
]
)
if __name__ == '__main__':
app.run()
设置缓存:
req -X POST -d '{\"key\":1,\"value\":111}' http://127.0.0.1:8888/zdppy_cache/set
获取缓存:
req -d '{\"key\":1}' http://127.0.0.1:8888/zdppy_cache/get
版本历史
v0.1.1
- 支持zpppy_api接口级别的缓存
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zdppy_cache-0.1.1.tar.gz
(40.1 kB
view details)
Built Distribution
File details
Details for the file zdppy_cache-0.1.1.tar.gz
.
File metadata
- Download URL: zdppy_cache-0.1.1.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dcf51c6befecb5fe5be147480cd42aaba42495dd8a1a7ca4359ef01a0459226 |
|
MD5 | d5d571e4de289f119b22736c7d55e05a |
|
BLAKE2b-256 | b1f81083f91730e5fda38b8b4dedf36963a90ea4f6c71b6a92af951674676e44 |
File details
Details for the file zdppy_cache-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: zdppy_cache-0.1.1-py3-none-any.whl
- Upload date:
- Size: 43.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f8be70609b8d5afdbdecbf9be852e5c904628f46d2f6e2481b04b74ab06bd1 |
|
MD5 | 08ba97ded45c7e048044c0734cd06d70 |
|
BLAKE2b-256 | f26c6c78044fbd3a5c3173e4135925e9fa1ec767d744faa55bafddacf460b17a |