dogpile缓存的文件系统后端
dogpile-filesystem的Python项目详细描述
dogpile缓存的文件系统后端
dogpile缓存的基于文件系统的后端。
后端的泛型变量paylogic.filesystem
将接受任何可选择的值,并将其存储在文件系统中。
原始变量paylogic.raw_filesystem
将只与类似文件的值一起工作,它将避免pickling阶段当您生成一个大文件并且不想将该文件的内容保存在内存中时,这非常有用。
两种变体都使用fcntl.lockf操作,因此它只与类unix系统兼容。 lockf系统调用允许使用同一文件分配任意数量的锁,从而避免删除锁文件时出现的问题
安装
使用pip安装:
$ pip install dogpile_filesystem
用法
通用变型
配置区域以使用paylogic.filesystem
:
fromdogpile.cacheimportmake_regionimportdatetimeregion=make_region().configure('paylogic.filesystem',arguments={"base_dir":"/path/to/cachedir",# Make sure this directory is only for this region# Optional parameters"cache_size":1024**3,# Defaults to 1 Gb"expiration_time":datetime.timedelta(seconds=30),# Defaults to no expiration"distributed_lock":True,# Defaults to true})@region.cache_on_arguments()defmy_function(args):return42
原始变量
配置区域以使用dogpile_文件系统:
fromdogpile.cacheimportmake_regionimportdatetimeimporttempfileregion=make_region().configure('paylogic.raw_filesystem',arguments={"base_dir":"/path/to/cachedir",# Make sure this directory is only for this region# Optional parameters"cache_size":1024**3,# Defaults to 1 Gb"file_movable":True,# Whether the backend can freely move the file.# When True, the backend will move the file to the cache# directory directly using os.rename(file.name).# When False (default), the content of the file will be copied to # the cache directory."expiration_time":datetime.timedelta(seconds=30),# Defaults to no expiration"distributed_lock":True,# Defaults to true})@region.cache_on_arguments()defbig_file_operation(args):# When using `file_movable=True`, we must make sure that NamedTemporaryFile does not delete the file on close,# otherwise it will complain that it cannot find the file.f=tempfile.NamedTemporaryFile(delete=False)# fill the filef.flush()f.seek(0)returnf
开发
以开发模式安装开发需求和项目:
$ pip install -r requirements_dev.txt -e .
运行测试:
$ pytest tests
可选地对所有支持的配置运行测试:
$ tox
更改日志
该项目的所有显著变化都将记录在本文件中。
这个项目遵循Semantic Versioning。
未发布
0.2.0条
- 删除了在
file_movable=True
但文件似乎不可移动时返回到复制文件的逻辑。不要试图变得聪明。
0.1.1
- 让pypi知道我们使用降价
0.1.0条
- 初始版本