flask-cache
flask-cache copied to clipboard
FileSystemCache throws exception
When using the file system cache, an exception occurs because werkzeug.contrib.cache.FileSystemCache init method expects the cache dir as its first argument and receives the Flask app object. The remaing args also do not match.
Don't know if this is an issue because of the werkzeug and Flask-Cache versions I use:
Flask-Cache==0.12 Werkzeug==0.9.4
Stack Trace
Traceback (most recent call last):
File "app.py", line 10, in <module>
cache = Cache(app)
File "/home/r/.virtualenvs/flask/local/lib/python2.7/site-packages/flask_cache/__init__.py", line 77, in __init__
self.init_app(app, config)
File "/home/r/.virtualenvs/flask/local/lib/python2.7/site-packages/flask_cache/__init__.py", line 109, in init_app
self._set_cache(app, config)
File "/home/r/.virtualenvs/flask/local/lib/python2.7/site-packages/flask_cache/__init__.py", line 138, in _set_cache
app, config, cache_args, cache_options)
File "/home/r/.virtualenvs/flask/local/lib/python2.7/site-packages/werkzeug/contrib/cache.py", line 593, in __init__
if not os.path.exists(self._path):
File "/home/r/.virtualenvs/flask/lib/python2.7/genericpath.py", line 18, in exists
os.stat(path)
TypeError: coercing to Unicode: need string or buffer, Flask found
What is your CACHE_TYPE config set to? It should be "filesystem".
I suppose it was set to filesystem, but the project has used a different caching mechanism since then.
I just ran into this defect, and it is as yaph describes. The method signatures do not match. flask-cache is instantiating werkzeug's FileSystemCache as
cache_obj(app, config, cache_args, cache_options)
but the werkzeug __init__
looks like:
def __init__(self, cache_dir, threshold=500, default_timeout=300, mode=0o600):
FYI, this is how I'm initializing the cache:
cache = Cache(app=app, config={'CACHE_TYPE': 'FileSystemCache', 'CACHE_DIR': '/tmp'})
Nevermind, I just re-read the docs, I was using FileSystemCache
instead of filesystem
. All is good now.
Could you create a pull request to make that part of the docs clearer? On Aug 9, 2014 9:58 AM, "vaamyob" [email protected] wrote:
Nevermind, I just re-read the docs, I was using FileSystemCache instead of filesystem. All is good now.
— Reply to this email directly or view it on GitHub https://github.com/thadeusb/flask-cache/issues/75#issuecomment-51688833.