dl.meteo
dl.meteo

Reputation: 1766

Can I use Flask-Caching without a Flask app?

I like the caching style of the Flask-Cache. So I want to ask if it is possible to use the flask cache (e.g. in combination with redis) for regular functions without a Flask app?

Something like this:

from flask_caching import Cache

cache = Cache('redis_server', config={'CACHE_TYPE': 'simple'})

@cache.cached()
def get_data_function(timestamp: datetime):
    return data[timestmap]

Upvotes: 1

Views: 741

Answers (1)

From what I can see from the source code of Flask-Cache, passing the flask instance is needed for it to work.

Personally, when I have a python application requiring caching with Redis, I go with Walrus. You can find it's documentation here.

The interface is quite similar to that of Flask-Cache so there won't be any issues in getting used to Walrus

Upvotes: 2

Related Questions