Skip to main content

A decorator that optimizes function execution by caching results. With support for different eviction strategies (LFU, LRU, FIFO).

Project description

Module: memo

.. image:: https://img.shields.io/badge/python-v3.6%7C3.7%7C3.8%7C3.9%7C3.10%7C3.11%7C3.12-blue :target: https://pypi.org/project/memocache/ :alt: Static Badge

.. image:: https://img.shields.io/pypi/l/memocache :target: https://pypi.org/project/memocache/ :alt: PyPI - License

Description: This module provides a memo decorator that implements a caching mechanism for function results. The goal is to optimize performance by avoiding redundant calculations.

Features:

  • Cache: Stores function call results in a local file.
  • Eviction strategies: Supports various eviction strategies (LRU, LFU, FIFO) to manage cache size.
  • Serialization: Uses serialization to store various data types in the cache.
  • Synchronization: Implements synchronization mechanisms to ensure cache integrity in multi-threaded environments.

Usage:

from memo import memo

@memo(strategy='lru', max_size=500)
def fibonacci(n):
    if n < 2:
        return n
    return fibonacci(n-1) + fibonacci(n-2)```

**Decorator parameters**:

* strategy: Eviction strategy (lru, lfu, fifo).
* max_size: Maximum cache size.
* ttl: Time-to-live of items in the cache (in seconds).
* Internal structure:

* cache_class: Class representing the cache (LRUCache, LFUCache, FIFOCache).
* evictor: Object responsible for managing cache item eviction.
* serialize/deserialize: Functions for serializing and deserializing data.
* cache_lock: Synchronization mechanism for cache access.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memocache-0.0.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

memocache-0.0.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file memocache-0.0.2.tar.gz.

File metadata

  • Download URL: memocache-0.0.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for memocache-0.0.2.tar.gz
Algorithm Hash digest
SHA256 31b6ead2ea5d828bd6549296419e534645186b152f38a4b6e0dec85514145e5b
MD5 88de59f2cb44553c9a0119e7151ba00f
BLAKE2b-256 99f27d023abaaf193ace3b1e7a317aac1a69379a90a43519bd6415e8cdd8a215

See more details on using hashes here.

File details

Details for the file memocache-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: memocache-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for memocache-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2afd2674a3e2c727339063a29499207e488547db42c996c861baf45ee8c0ca7
MD5 3cf309f9b096b6bf7daebd7e71304f0a
BLAKE2b-256 304400d3ee7b22bee4d4c71c046c70934616f17daa1cbf17fcd7ffce45cce234

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page