GithubHelp home page GithubHelp logo

memoizepy's Introduction

memoizepy

Use to memoize a function using Redis.

This is useful when you may rerun a long-running function many times. It will cache the value the first time, and return the cached value on subsequent runs with the same arguments and the same function names.

It uses a 128-bit hash of function name, and function arguments.

Note named args in a different order are considered different runs so will not cache-map to one another.

Relies on Redis on default port and localhost. This can be changed if desired by updating the get and store functions.

This code is multiprocessing pool aware as the decorated function is pickleable thanks to functools.

Works on Numpy and Pandas.

Works on 2.7 and 3.x. Be careful to ensure a fast pickle is installed, that's cPickle. Usually 3.x std lib pickle is fast by default.

usage:

from memoizepy import memoize

@memoize
def some_fun_to_memoize(x, y, z):
    return x + y + z

some_fun_to_memoize(1, 2, 3)   # this will calculate
>>> 6               

some_fun_to_memoize(1, 2, 3)   # this will return from cache
>>> 6               

There are some long-running really numerically intensive decorated functions in memoizetest.py for your perusal, namely longrun_eig and primes_between.

run from command line python memoizepy.py for a speed test

Use of Redis means multiple users can share cached calculations if using the same Redis server.

memoizepy's People

Contributors

vegabook avatar

Watchers

 avatar  avatar

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.