Skip to main content

dcache

PyPI Coverage Status Documentation Status

Distributed Cache for Humans

Installation

pip install dcache

How to Use

  • TODO

Contributing

Contributions are welcome, feel free to open an Issue or Pull Request.

Pull requests must be for the develop branch.

git clone https://github.com/HBN3tw0rk/dcache
cd dcache
git checkout develop
python -m venv .venv
pip install -r requirements_dev.txt
pre-commit install
pytest

Pitch (Portuguese)

What is

  • distributed cache for humans

  • simple API like lru_cache

  • multiple backends

  • easy to switch the backend

  • good documentation

API

dcache

from dcache import dcache

@dcache
def slow_function(n):
    return n ** 1000

dcache vs redis

import redis
redis = redis.Redis(host='localhost', port=6379, db=0)

def slow_function(n):
    cached = redis.get(n)
    if cached:
        return cached
    value = n ** 1000
    redis.set(n, value)
    return value

def slow_function2(n):
    cached = redis.get(n)
    if cached:
        return cached
    value = n ** 1000
    redis.set(n, value)
    return value
from dcache import cache
from dcache.backends import RedisBackend

cache = dcache(RedisBackend(host='localhost', port=6379, db=0))

@cache
def slow_function(n):
    return n ** 1000

@cache
def slow_function2(n):
    return n ** 1000

real example

def process(id, input):
    cache_path = get_content_cache_path(id, input)

    if resource.file_exist(cache_path):
        return resource.get_json(cache_path)

    response = slow_function(id, input)
      resource.put_json(body=response, file_path=cache_path)
    return response
from dcache import dcache
from dcache.backends import S3Backend

@dcache(S3Backend())
def process(id, input):
    return slow_function(id, input)

Ideas

  • integration tests using containers

multiple backends

from dcache import dcache
from dcache.backends import InMemoryBackend, RedisBackend

@dcache(multiple=[
    InMemoryBackend(),
    RedisBackend(host='localhost', port=6379, db=0),
])
def slow_function(n):
        return n ** 1000
  1. search on the in-memory cache;

  2. if exists, return, if not, search on Redis;

    • if exists on Redis, save in memory and return;

    • if not, exists on Redis, run the slow_function, save on Redis, save in-memory and return;

  • doesn’t run if already returned

MVP

  • in memory

Roadmap

  • backends: Redis, Memcached, Filesystem, database, S3, etc.

  • multiple backends

  • plugins

Changelog

(unreleased)

  • Add InMemory backend

0.0.1 (2022-07-30)

  • First release on PyPI.

Download files

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

Source Distribution

dcache-0.0.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dcache-0.0.2-py2.py3-none-any.whl (14.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: dcache-0.0.2.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for dcache-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2142a1acd679bd799a1a0317c90db048eb0ab1e2fb1337fa9ff8fe80dc612e1d
MD5 05c9441c348f52afa22f98a281cfa723
BLAKE2b-256 6fcb7eb72963636cb449bcd73738909f951a8e6915faae1fdb959b5332662490

See more details on using hashes here.

File details

Details for the file dcache-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: dcache-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for dcache-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 32ca2b762bf30a6d7458e493f26c974acee708107bdcd8245ecff9f08cda4b87
MD5 fc5425db674a719e60809e44546e03af
BLAKE2b-256 a49b1cc6c944d8da6cc59bf5ce52722bdb29a3412b3ac876d39863e264c9da76

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page