Automatic Flask cache configuration on Heroku.

Overview

flask-heroku-cacheify

Automatic Flask cache configuration on Heroku.

Thinking Man Sketch

Purpose

Configuring your cache on Heroku can be a time sink. There are lots of different caching addons available on Heroku (Redis, Memcached, etc.), and among those -- lots of competitors.

flask-heroku-cacheify makes your life easy by automatically configuring your Flask application to work with whatever caching addons you've got provisioned on Heroku, allowing you to easily swap out addon providers at will, without any trouble. And, just in case you don't have any suitable Heroku addons available, flask-heroku-cacheify will default back to using local memory for your cache!

Instead of looking through documentation, testing stuff out, etc., flask-heroku-cacheify will just do everything for you :)

Install

To install flask-heroku-cacheify, use pip.

$ pip install flask-heroku-cacheify

NOTE: If you're install flask-heroku-cacheify locally, you'll need to have libmemcached-dev installed on your OS (with SASL support).

Next, modify your requirements.txt file in your home directory, and add the following to the bottom of your file:

Flask-Heroku-Cacheify>=1.3
pylibmc>=1.2.3

The above will ensure that Heroku pulls in the required C header files (in case you decide to use memcached). This step is required.

Pick an Addon

Heroku has lots of available addons you can use for caching. flask-heroku-cacheify currently works with them all! That means no matter which option you choose, your cache will work out of the box, guaranteed!

Below is a list of the addons you can install to get started, you should have at least one of these activated on your Heroku app -- otherwise, your cache will be in 'local memory' only, and won't be very useful.

NOTE My favorite providers are MemCachier (for memcache), and openredis for redis. Both are equally awesome as cache providers. If you're in need of a stable cache provider for large applications, I'd recommend RedisGreen -- they use dedicated EC2 instances (which greatly improves your server power) and have an excellent interface.

Usage

Using flask-heroku-cacheify is super easy! In your app.py (or wherever you define your Flask application), add the following:

from flask_cacheify import init_cacheify

app = Flask(__name__)
cache = init_cacheify(app)

Once you've got your cache global defined, you can use it anywhere in your Flask app:

>>> from app import cache
>>> cache.set('hi', 'there', 30)
>>> cache.get('hi')
'there'

How does this work? In the background, flask-heroku-cacheify is really just automatically configuring the popular Flask-Cache extension! This means, you can basically skip down to this part of their documentation, and begin using all the methods listed there, without worrying about setting up your caches! Neat, right?

For more information and examples of how to use your cache, don't forget to read the Flask-Cache documentation.

Like This?

Like this software? If you really enjoy flask-heroku-cacheify, you can show your appreciation by:

  • Sending me some bitcoin, my address is: 17BE6Q6fRgxJutnn8NsQgeKnACFjzWLbQT
  • Tipping me on gittip.

Either way, thanks! <3

Changelog

1.6.1: 12-20-2017

- Update docs
- Updating code to support latest Flask release

1.6.0: 04-22-2017

- Upgrading to work with latest FLask release (thanks @mattstibbs).

v1.5: 06-20-2015

- Removing MyRedis addon support -- the addon has been shut down.

v1.4: 04-04-2015

- Fixing typos in README.
- Adding Python 3 compatibility.

v1.3: 05-31-2012

- Fixing bug with memcachier support (thanks @eriktaubeneck)!

v1.2: 04-18-2013

- Adding proper documentation.

v1.1: 04-18-2013

- Adding support for MyRedis.
- Adding support for Redis Cloud.
- Adding support for Redis To Go.
- Adding support for openredis.

v1.0: 04-18-2013

- Fixing bug with RedisGreen support.

v0.9: 04-18-2013

- First *real* release! Supports MemCachier and RedisGreen!

v0.8: 04-18-2013

- Pushing eigth release to PyPI (don't use this still!).

v0.7: 04-18-2013

- Pushing seventh release to PyPI (don't use this still!).

v0.6: 04-18-2013

- Pushing sixth release to PyPI (don't use this still!).

v0.5: 04-18-2013

- Pushing fifth release to PyPI (don't use this still!).

v0.4: 04-18-2013

- Pushing fourth release to PyPI (don't use this still!).

v0.3: 04-18-2013

- Pushing third release to PyPI (don't use this still!).

v0.2: 04-18-2013

- Pushing second release to PyPI (don't use this still!).

v0.1: 04-18-2013

- Pushing first release to PyPI (don't use this yet!).

v0.0: 04-14-2013

- Started work >:)
Comments
  • Usage with app factory?

    Usage with app factory?

    This looks like a great project! I can't figure out how to use it in an app factory though. Here is my setup

    __init__.py

    import config
    from flask import Flask
    from flask.ext.sqlalchemy import SQLAlchemy
    from flask.ext.cacheify import init_cacheify
    
    db = SQLAlchemy()
    
    def create_app(config_mode=None, config_file=None):
        app = Flask(__name__)
        app.register_blueprint(blueprint)
        db.init_app(app)
        cache = init_cacheify(app)
    
        if config_mode:
            app.config.from_object(getattr(config, config_mode))
        elif config_file:
            app.config.from_pyfile(config_file)
        else:
            app.config.from_envvar('APP_SETTINGS', silent=True)
    
        return app
    
    from app.views import blueprint
    

    views.py

    from flask import Blueprint, make_response
    from app import cache
    
    blueprint = Blueprint('blueprint', __name__)
    
    @cache.memoize(timeout=50)
    def big_foo(a, b):
        return a + b + random.randrange(0, 1000)
    
    ...
    

    I get the following error ImportError: cannot import name cache since cache is defined in the app factory and not globally (like db).

    opened by reubano 9
  • flask.ext.cacheify is not working any more

    flask.ext.cacheify is not working any more

    I also can't find it on http://flask.pocoo.org/extensions/

    I have followed the instructions in the readme, and everything was working fine..until today.

    I get the following error: ImportError: No module named flask.ext.cacheify

    Do you know why this is occurring/an alternate solution to installing this awesome extension?

    opened by peoplecallmefrancois 3
  • Does Not Work With Redis To Go

    Does Not Work With Redis To Go

    Unfortunately, the server just hangs whenever I use a cached view with Redis To Go.

    It works with Memcachier though.

    Do you know why it may not be working with Redis To Go?

    I've heard Redis is better than Memecache that's why I was hoping to use Redis To Go (since it's the only free Redis option available).

    P.S. This is a great library, it saved me time trying to figure out how to set the cache up on Heroku, so thank you!

    opened by peoplecallmefrancois 2
  • Importing flask.ext.cacheify is deprecated

    Importing flask.ext.cacheify is deprecated

    First thing, thank you for an amazing library! It was so easy to set up, I just followed the instructions, ran it once, and it worked! Just reporting a few warnings I'm getting:

    /app/.heroku/python/lib/python3.6/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cacheify is deprecated, use flask_cacheify instead.
    

    I made that change in my app, and then got

    /home/rkuykendall/.local/lib/python3.6/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
    

    Everything is working, but I thought you would want to know.

    opened by rkuykendall 1
  • Update depedency from Flask-Cache to Flask-Caching

    Update depedency from Flask-Cache to Flask-Caching

    Flask-Cache is apparently dormant, and is not compatible with the latest version of Flask.

    This PR updates the depency from Flask-Cache to a fork of the project called Flask-Caching which appears to be more actively maintained.

    Resolves #14

    See issue notes for more details about why this is suggested option.

    opened by mattstibbs 0
  • Not compatible with Flask >1.0.0

    Not compatible with Flask >1.0.0

    Since Flask v1.0.0, the flask.ext.* syntax has been deprecated.

    Flask-Heroku-Cacheify depends on Flask-Cache, which is now apparently dormant. Looking at the repository, pull requests have not been responded to for a very long time. Therefore there is no obvious way to get this fixed in the upstream dependency.

    Suggested resolution: update Flask-Heroku-Cacheify to depend on the newer fork Flask-Caching https://github.com/sh4nks/flask-caching

    opened by mattstibbs 0
Owner
Randall Degges
I'm just a happy programmer that likes to hack stuff.
Randall Degges
Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.

DiskCache is an Apache2 licensed disk and file backed cache library, written in pure-Python, and compatible with Django.

Grant Jenks 1.7k Jan 5, 2023
An ORM cache for Django.

Django ORMCache A cache manager mixin that provides some caching of objects for the ORM. Installation / Setup / Usage TODO Testing Run the tests with:

Educreations, Inc 15 Nov 27, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
johnny cache django caching framework

Johnny Cache is a caching framework for django applications. It works with the django caching abstraction, but was developed specifically with the use

Jason Moiron 304 Nov 7, 2022
RecRoom Library Cache Tool

RecRoom Library Cache Tool A handy tool to deal with the Library cache file. Features Parse Library cache Remove Library cache Parsing The script pars

Jesse 5 Jul 9, 2022
Peerix is a peer-to-peer binary cache for nix derivations

Peerix Peerix is a peer-to-peer binary cache for nix derivations. Every participating node can pull derivations from each other instances' respective

null 92 Dec 13, 2022
Robust, highly tunable and easy-to-integrate in-memory cache solution written in pure Python, with no dependencies.

Omoide Cache Caching doesn't need to be hard anymore. With just a few lines of code Omoide Cache will instantly bring your Python services to the next

Leo Ertuna 2 Aug 14, 2022
Automatic caching and invalidation for Django models through the ORM.

Cache Machine Cache Machine provides automatic caching and invalidation for Django models through the ORM. For full docs, see https://cache-machine.re

null 846 Nov 26, 2022
A caching extension for Flask

Flask-Caching Adds easy cache support to Flask. This is a fork of the Flask-Cache extension. Flask-Caching also includes the cache module from werkzeu

Peter Justin 774 Jan 2, 2023
Iris-Heroku - Putting a Machine Learning Model into Production with Flask and Heroku

Puesta en Producción de un modelo de aprendizaje automático con Flask y Heroku L

Jesùs Guillen 1 Jun 3, 2022
A Web API for automatic background removal using Deep Learning. App is made using Flask and deployed on Heroku.

Automatic_Background_Remover A Web API for automatic background removal using Deep Learning. App is made using Flask and deployed on Heroku. ?? https:

Gaurav 16 Oct 29, 2022
Django package to log request values such as device, IP address, user CPU time, system CPU time, No of queries, SQL time, no of cache calls, missing, setting data cache calls for a particular URL with a basic UI.

django-web-profiler's documentation: Introduction: django-web-profiler is a django profiling tool which logs, stores debug toolbar statistics and also

MicroPyramid 77 Oct 29, 2022
Jira-cache - Jira cache with python

Direct queries to Jira have two issues: they are sloooooow many queries are impo

John Scott 6 Oct 8, 2022
A slick ORM cache with automatic granular event-driven invalidation.

Cacheops A slick app that supports automatic or manual queryset caching and automatic granular event-driven invalidation. It uses redis as backend for

Alexander Schepanovski 1.7k Dec 30, 2022
A slick ORM cache with automatic granular event-driven invalidation.

Cacheops A slick app that supports automatic or manual queryset caching and automatic granular event-driven invalidation. It uses redis as backend for

Alexander Schepanovski 1.7k Jan 3, 2023
Read configuration settings from python configuration files.

Maison Read configuration settings from python configuration files. Motivation When developing a python application, e.g a command-line tool, it can b

null 9 Jan 4, 2023
Search users in Github. Created with Flask, PipEnv, Heroku and free time.

Search in Github Here search for users in Github and other stuff! This app is working with, Data Github API BackEnd Flask Language Python Package mana

AmirHossein Mohammadi 12 Jan 16, 2022
flask-apispec MIT flask-apispec (🥉24 · ⭐ 520) - Build and document REST APIs with Flask and apispec. MIT

flask-apispec flask-apispec is a lightweight tool for building REST APIs in Flask. flask-apispec uses webargs for request parsing, marshmallow for res

Joshua Carp 617 Dec 30, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 124 Jan 22, 2021