python基于sqlite线程安全/进程安全的缓存-有趣儿的脑洞

Posted 70 months ago sqlite k/v python cache

Python disk backed cache

说是基于磁盘 实际上再linux上新建一个内存盘 把sqlite文件设置到内存盘中就可以了

安装


pip install diskcache

使用


import diskcache

#设置文件到内存中。=。  速度还不错
cache = diskcache.Cache("/tmp")


#写入缓存
cache.set(
    key="key",
    value="内容",
    expire="过期时间",
    tag="命名空间”
)


#手动清除超过生存时间的缓存
cache.cull()

#清除命名空间的缓存
cache.evict()

号称 Thread-safe and process-safe 经过测试还不错!

点击评论