Flask-Cache Stats

Flask-cache-stats is an extension for flask that extends flask-cache extension in order to provide modest amount of cache usage statistics. It hooks into the existing getter and setter methods of the cache backends to update a log file. The extension can then be registered as a blueprint so that the stats can be viewed as a table.

Usage

Flask-cache-stats provides the same API’s as flask-cache extension, so you just need to replace all the imports and you are good to go.

# replace
from flask_cache import Cache
# with
from flask_cache_stats import Cache

The view for displaying the data table can be registered using the CacheStats blueprint. The blueprint is extensible that you can completely customize the behavior of the view. The class provides a delete rest API that can be used to clear a key from the cache. In order to make use of this API, you would need to install and setup flask-login extension.

class CacheStats(Blueprint):
    def __init__(self, cache_obj, base_template="base.html",
                 enable_clear_api=False, protect_api=True,
                 cache_template="stats_view.html",
                 url_prefix='/cache_stats')

# Usage
app = Flask(__name__)
app.config['CACHE_TYPE'] = 'simple'
cache = Cache(app)
stats_bp = CacheStats(cache, enable_clear_api=False)

Below is an example showing the usage of flask-cache-stats.

Msldata cache usage example
Msldata cache usage example

References and Links

  1. Flask-cache-stats