为Dogpile Cache的文件系统后端
项目描述
为Dogpile Cache的文件系统后端
基于文件系统的dogpile cache后端。
后端的通用变体paylogic.filesystem
将接受任何可序列化的值,并将其存储在文件系统中。
原始变体paylogic.raw_filesystem
仅与文件值一起工作,并避免序列化阶段。当你正在生成大文件并且不想在内存中保留该文件的内容时,这非常有用。
两个变体都使用fcntl.lockf
操作,因此仅与类UNIX系统兼容。lockf系统调用允许使用相同的文件分配任意数量的锁,避免了删除锁文件时出现的问题。
安装
使用pip安装
使用pip安装dogpile_filesystem
用法
通用版本
配置一个区域使用paylogic.filesystem
from dogpile.cache import make_region
import datetime
region = 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()
def my_function(args):
return 42
原始版本
配置一个区域使用dogpile_filesystem
from dogpile.cache import make_region
import datetime
import tempfile
region = 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()
def big_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 file
f.flush()
f.seek(0)
return f
开发
安装开发需求并以开发模式运行项目
$ pip install -r requirements_dev.txt -e .
运行测试
$ pytest tests
可选:运行所有支持的配置的测试
$ tox
变更日志
本项目所有显著更改都将记录在此文件中。
本项目遵循语义版本规范。
未发布
0.2.0
- 移除当
file_movable=True
但文件看起来不可移动时回退到复制文件的逻辑。不要试图变得聪明。
0.1.1
- 让PyPI知道我们使用markdown
0.1.0
- 首次发布
项目详情
关闭
dogpile_filesystem-0.2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fc71ef1e2ad47ac5e936bbf2b4069b9426d330d8e6e4915aaccffcd4fff16620 |
|
MD5 | ffb282de0fb44838dfda1eaac9c2079f |
|
BLAKE2b-256 | c34830a00646ac4d760d68b16e8cb5f35448afa27c198eca4d27d8176f33f9c8 |