I'm using flask-cache in an app and trying to prepopulate the cache in a separate process. The problem is I can't figure out the format the cached values are stored in.
Looking at the cached values they look like they've been pickled, but the values created by cached functions are slightly different from normal pickled values and can't be unpickled directly. Here's an example:
Here is my flask view:
@app.route('/index')
@cache.cached(timeout=60)
def index():
return 'foo'
Here is the cached value from my view, stored in redis:
>>> r = redis.StrictRedis()
>>> r.keys()
[b'flask_cache_view//index']
>>> r.get('flask_cache_view//index')
b'!\x80\x03X\x03\x00\x00\x00fooq\x00.'
Notice the cached bytestring has a leading '!'. Compare to manually pickling 'foo':
>>> import pickle
>>> pickle.dumps('foo')
b'\x80\x03X\x03\x00\x00\x00fooq\x00.'
The latter can be unpickled, but attempting to unpickle the flask-cache value results in an error "_pickle.UnpicklingError: invalid load key, '!'."
Because I don't fully understand the problem I'm not comfortable implementing a solution (e.g. removing / prepending '!' on all bytestrings). Am I on the right track here?