Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Repository files navigation

dcache

PyPICoverage StatusDocumentation 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

fromdcacheimportdcache@dcachedefslow_function(n):
returnn**1000

dcache vs redis

importredisredis=redis.Redis(host='localhost', port=6379, db=0)
defslow_function(n):
cached=redis.get(n)
ifcached:
returncachedvalue=n**1000redis.set(n, value)
returnvaluedefslow_function2(n):
cached=redis.get(n)
ifcached:
returncachedvalue=n**1000redis.set(n, value)
returnvalue
fromdcacheimportcachefromdcache.backendsimportRedisBackendcache=dcache(RedisBackend(host='localhost', port=6379, db=0))
@cachedefslow_function(n):
returnn**1000@cachedefslow_function2(n):
returnn**1000

real example

defprocess(id, input):
cache_path=get_content_cache_path(id, input)
ifresource.file_exist(cache_path):
returnresource.get_json(cache_path)
response=slow_function(id, input)
resource.put_json(body=response, file_path=cache_path)
returnresponse
fromdcacheimportdcachefromdcache.backendsimportS3Backend@dcache(S3Backend())defprocess(id, input):
returnslow_function(id, input)

Ideas

  • integration tests using containers

multiple backends

fromdcacheimportdcachefromdcache.backendsimportInMemoryBackend, RedisBackend@dcache(multiple=[InMemoryBackend(),RedisBackend(host='localhost', port=6379, db=0),])defslow_function(n):
returnn**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

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages