hehey-hcache 组件
介绍
hehey-hcache 是一个python 数据缓存工具组件
依赖以及版本要求
- python >= 3.5
安装
- 直接下载:
- 命令安装:
pip install hehey-hcache
基础文件以目录
参数配置
conf = {
'keyPrefix': "yi",
'defaultStorage':'memcached',
'customStorages': {
# redis 远程存储 配置
'redis': {
'clazz': 'hcache.storages.RedisStorage.RedisStorage',
'red': {'host': '127.0.0.1', 'port': 6379, 'db': 1, 'password': ""}
},
# file 文件配置
'file': {
'clazz': 'hcache.storages.FileStorage.FileStorage',
'cachePath': '/home/hehe/www/cache',
'dirLevel':2,
},
# 本地内存配置
'local': {
'clazz': 'hcache.storages.LocalStorage.LocalStorage',
'options':{
'mode': 'lru',
}
},
# memcached远程存储配置
'memcached': {
'clazz': 'hcache.storages.MemcachedStorage.MemcachedStorage',
'mc': {
'servers': ['127.0.0.1:11211'],
}
}
},
}
# 支持四种存储,redis,file,memcached,local(进程内存)
# keyPrefix: key 前缀
# defaultStorage: 默认存在类型,比如redis
基本示例
- 快速使用
from hcache.cache import CacheManager;
conf = {
'keyPrefix': "yi",
'defaultStorage':'memcached',
'customStorages': {
# redis 远程存储 配置
'redis': {
'clazz': 'hcache.storages.RedisStorage.RedisStorage',
'red': {'host': '127.0.0.1', 'port': 6379, 'db': 1, 'password': ""}
},
# file 文件配置
'file': {
'clazz': 'hcache.storages.FileStorage.FileStorage',
'cachePath': '/home/hehe/www/cache',
'dirLevel':2,
},
},
}
hcache = CacheManager(conf)
# 设置缓存
hcache.set("accountInfo",{"realName":"hehe","stauts":1})
hcache.set("name","hahahxxxx",expire = 20)
# 获取缓存
hcache.get("name")
hcache.get("accountInfo")
- 批量设置/批量获取
from hcache.cache import CacheManager;
conf = {
'keyPrefix': "yi",
'defaultStorage':'memcached',
'customStorages': {
# redis 远程存储 配置
'redis': {
'clazz': 'hcache.storages.RedisStorage.RedisStorage',
'red': {'host': '127.0.0.1', 'port': 6379, 'db': 1, 'password': ""}
},
# file 文件配置
'file': {
'clazz': 'hcache.storages.FileStorage.FileStorage',
'cachePath': '/home/hehe/www/cache',
'dirLevel':2,
},
},
}
hcache = CacheManager(conf)
# 批量设置
datas = {"account":{"realName":"hehe"},"address":{"cityId":1,"userId":20}};
hcache.mset(datas,expire = 20)
# 批量获取
hcache.mget("account","address")
# 或
hcache.mget(["account","address"])
- 检验key 是否存在
from hcache.cache import CacheManager;
conf = {};
hcache = CacheManager(conf)
if hcache.exists("account"):
print("yes")
else:
print("no")
- 直接使用存储set/get
from hcache.cache import CacheManager;
conf = {
'keyPrefix': "yi",
'defaultStorage':'memcached',
'customStorages': {
# redis 远程存储 配置
'redis': {
'clazz': 'hcache.storages.RedisStorage.RedisStorage',
'red': {'host': '127.0.0.1', 'port': 6379, 'db': 1, 'password': ""}
},
# file 文件配置
'file': {
'clazz': 'hcache.storages.FileStorage.FileStorage',
'cachePath': '/home/hehe/www/cache',
'dirLevel':2,
},
},
}
hcache = CacheManager(conf)
hcache.file.set("accountInfo",{"realName":"hehe","stauts":1})
hcache.file.set("name","hahahxxxx",expire = 20)
# 获取缓存
hcache.file.get("name")
hcache.file.get("accountInfo")
- 装饰器注解缓存数据
from hclient.client import Client;
Metadata
Release files for hehey-hcache 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hehey-hcache-1.0.2.tar.gz | 12.3 kB | Without provenance | Details for hehey-hcache-1.0.2.tar.gz |
Release files / hehey-hcache-1.0.2.tar.gz
| Download URL | hehey-hcache-1.0.2.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7442ca098de2f00a44b00529ba8b6245bba685bb094b897c8f80d39140750e29
|
|
BLAKE2b-256 checksum How to use checksums |
b00f1ff33490c894e01a4d4e439406b7b8434b9b04f4e5330864c4f719ec24cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/20.7.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.8
|
Security for hehey-hcache 1.0.2
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.