Giter Site home page Giter Site logo

kpn / cachetory Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 6.0 794 KB

Caching library with support for multiple cache backends

Home Page: https://kpn.github.io/cachetory/

License: Apache License 2.0

Makefile 0.82% Python 99.18%
cache python-library python-package async-cache memory-cache redis-cache cache-decorators dummy-cache asynchronous synchronous caching pypi-package django-cache

cachetory's Introduction

Cachetory

PyPI Python versions Checks Coverage Code style

Documentation

Documentation

Sneak peak

from cachetory import serializers
from cachetory.backends import async_ as async_backends
from cachetory.caches.async_ import Cache


cache = Cache[int, bytes](
    serializer=serializers.from_url("pickle://?pickle-protocol=4"),
    backend=async_backends.from_url("redis://localhost:6379"),
)

async def main() -> None:
    await cache.set("foo", 42)
    assert await cache.get("foo") == 42

cachetory's People

Contributors

candalay avatar dependabot[bot] avatar eigenein avatar jeroennc avatar renovate[bot] avatar ricardosantosalves avatar wpeterw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cachetory's Issues

Implement JSON serializer

This may offer optional dependencies and maybe parameters to enable the non-standard serializers:

Maybe we'd want to implement them as different serializers since they may provide different sets of options.

Implement SQLite backend

It was originally requested in aiocache: aio-libs/aiocache#486. I'm not sure whether it's beneficial, but let's track the idea.

Keep in mind:

  • Initializing of database schema, preferably idempotent
  • Configuring of table name

Implement memcached backend

This one is not gonna be as straightforward as, for example, Redis. So I'm not sure if we want to implement it from scratch or just use something like aiomcache and adapt it to our backend protocol.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (pinOnlyDevDependencies)

Implement `@cached_many`

Suggested use case:

@cached_many(cache)
def expensive_function(items: Iterable[K], …) -> Mapping[K, V]:
    …

expensive_function(["foo", "bar", "qux"], …)

Expected behaviour

expensive_function should get called only on items which aren't present in the cache. Pseudo-code:

cached_items = cache.get_many(*items)
new_items = wrapped_function(*(item for item in items if item not in cached_items), *args, **kwargs)
cache.set_many(new_items)
return {**cached_items, **new_items}

Discussion

  • Should @cached_many allow specifying of the items parameter by index or keyword argument name?

Implement a codec (?) serializer

For example, JsonSerializer would return a str, but ZstdCompressor expects a bytes. So, we'd need some layer in-between to encode/decode a string into/from bytes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.