Git Product home page Git Product logo

mnemon's Introduction

μνήμων

A simple cache interface for Python objects. Abuse it.

There are many other caching libraries but this one is very minimal and it's meant to stay so.

Will add more documentation soon.

Simple usage

from mnemon import mnc

c = mnc()
c[0] = 1
print(c[0])     # returns 1 (obviously)
c.expire(0, 5)  # expires in 5 seconds

del c[0]

Can be used in with. (with mnc() as c: ...). This has no effect on the redis backend.

Decorator usage

from mnemon import mnd as mn

@mn
def f(x):
    return x

Caveats

  • Default backend (be param to both mnc and mnd) is redis. If Redis isn't found it will fall back to the file backend.
  • The file backend gets cleaned up every time mnc() is called, or on __exit__.
  • Caching by default pickles and compresses (zlib) the objects. Initialising mnc or mnc with raw=True bypasses pickling but assumes you're caching strings or bytes. Good to cache HTTP request results, bad for most other cases. Use raw only with strings.
  • Compression is currently mandatory.
  • For now nothing can be configured at runtime besides constructor parameters.

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.