跳转到主要内容

为Dogpile Cache的文件系统后端

项目描述

为Dogpile Cache的文件系统后端

PyPI Build Status Coverage Status

基于文件系统的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 (12.8 kB 查看哈希值)

上传时间 源代码

由以下支持