Code Monkey home page Code Monkey logo

multicache's Introduction

Multicache

Build Status Coverage Status

Simple python caching mechanisms using expiration time or time to live.

Designed to be used with API clients and similar.

This module aims primarily to be simple and easy to use and extend. It doesn't remove expired data unless you try to get it from cache.

Installation

pip install multicache

or

git clone [email protected]:bargulg/multicache.git
cd multicache
python setup.py install

optionally for redis cache:

pip install redis

Usage

from multicache import DictCache

cache = DictCache()

def search_with_cache(query='python'):
    headers = {'User-Agent': 'Mozilla/5.0'}
    request_url = 'https://duckduckgo.com'
    params = {'q': query}

    request_url = "{}?{}".format(url, urlencode(params))

    cached = cache.get(request_url)
    if cached:
        return cached
    else:
        req = Request(request_url, headers=headers)
        response = json.loads(urlopen(req).read().decode("utf-8"))
        cache.put(request_url, response)
        return response

Types of cache

RedisCache (recommended)

Saves data in redis - fast, lightweight and reliable Right now this supports only default redis settings, better support for redis will come soon

DictCache

Saves data in dict - this will be deleted when program is closed

FileCache

Saves data in file as a persistent storage, good for long-term caching of small number of keys. For speed, it also saves it in dict, and reads file whenever it doesn't find key in dict.

DummyCache

Doesn't save anything, every call to get(key) is a cache miss

Your own custom, fancy cache

Just inherit from BaseCache and implement put(), get(), and invalidate()

multicache's People

Contributors

bargulg avatar

Stargazers

Milan Kubík avatar

Watchers

 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.