Skip to main content

File Memoizer

license PyPi:version Tests Release

NOTICE: This package is deprecated and will no longer be updated, as the functionality it provides has now been inplemented directly in cachier. Please use that package directly.

Installation

Installation is via pip:

pip install file-memoizer

Usage

To cache a function's value, annotate it by calling the memoize function as follows. Note that all function arguments must be hashable for it to be cached else a TypeError will be thrown.

import file_memoizer

@file_memoizer.memoize()
def double(n):
    return 2 * n

By default the cached values remain valid for a day. This can be changed with the cache_ttl parameter:

import datetime
import file_memoizer

seven_days = cache_ttl=datetime.timedelta(days=7)

@file_memoizer.memoize(cache_ttl=seven_days)
def triple(n):
    return 3 * n

Cache files are stored in $HOME/.file-memoizer, with one file per combination of input parameters. An alternate location can be specified with the cache_directory parameter:

import datetime
import file_memoizer

custom_path = '/path/to/store/files'

@file_memoizer.memoize(cache_directory=custom_path)
def quadruple(n):
    return 4 * n

The memoizer will automatically ignore a function's first parameter if named self, so that instance methods can be cached. It is the caller's responsibility to ensure the result of the method does not depend on the state of the object's internals. This is most useful when the object is being used to call an external service.

import requests

class ExampleAPIClient():

    @file_memoizer.memoize()
    def get(self, url):
        return self.session.get(url)

    def __init__(self):
        self.session = requests.Session()

Metadata

Release files for file-memoizer 0.4.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 file-memoizer 0.4.0
File Size Uploaded Provenance
file_memoizer-0.4.0.tar.gz 2.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for file-memoizer 0.4.0
File Interpreter ABI Platform
file_memoizer-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 kB

Release files / file_memoizer-0.4.0.tar.gz

Download URL file_memoizer-0.4.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b550a26759f16003d0713164cf5733cecc662fd0e03ab3bc49d617ce6f6a48d6
BLAKE2b-256 checksum
How to use checksums
30ef92a4d50e6c7eb78171fba75c524c2b079406925a8966d8dfbfa1774e6a25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure

Release files / file_memoizer-0.4.0-py3-none-any.whl

Download URL file_memoizer-0.4.0-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe1f6a7c59c936997ea238dc02638d5bf1c13a7756cf99b21ba70386be1a52da
BLAKE2b-256 checksum
How to use checksums
cf399536583b929fcdf6db43fd30b53f7aec601420ac963b3297577c43aafbd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure

Security for file-memoizer 0.4.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.

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