Skip to main content

File System Backends for Dogpile Cache

PyPI Build Status Coverage Status

Filesystem-based backends for dogpile cache.

The generic variant of the backend, paylogic.filesystem, will accept any picklable value and it will store it in the file system.

The raw variant paylogic.raw_filesystem will only work with file-like values and it will avoid the pickling phase. This is useful when you are generating a big file and you don't want to keep in memory the contents of this file.

Both variants use fcntl.lockf operations, therefore it is compatible with UNIX-like systems only. The lockf system call allows to allocate an arbitrary number of locks using the same file, avoiding problems that arise when deleting lock files.

Installation

Install with pip:

$ pip install dogpile_filesystem

Usage

Generic variant

Configure a region to use 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

Raw variant

Configure a region to use 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

Development

Install the dev requirements and the project in development mode:

$ pip install -r requirements_dev.txt -e .

Run tests:

$ pytest tests

Optionally run tests for all supported configurations:

$ tox

Changelog

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

Unreleased

0.2.0

  • Removed logic that falls back to copying a file when file_movable=True but the file does not appear to be movable. Do not try to be smart.

0.1.1

  • Let PyPI know that we use markdown

0.1.0

  • Initial release

Metadata

Release files for dogpile-filesystem 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dogpile-filesystem 0.2.0
File Size Uploaded Provenance Actions
dogpile_filesystem-0.2.0.tar.gz 12.8 kB Without provenance Details for dogpile_filesystem-0.2.0.tar.gz

Release files / dogpile_filesystem-0.2.0.tar.gz

Download URL dogpile_filesystem-0.2.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fc71ef1e2ad47ac5e936bbf2b4069b9426d330d8e6e4915aaccffcd4fff16620
BLAKE2b-256 checksum
How to use checksums
c34830a00646ac4d760d68b16e8cb5f35448afa27c198eca4d27d8176f33f9c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

Security for dogpile-filesystem 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page