flask-cache icon indicating copy to clipboard operation
flask-cache copied to clipboard

FileSystemCache throws exception

Open yaph opened this issue 11 years ago • 6 comments

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

yaph avatar Oct 22 '13 21:10 yaph

What is your CACHE_TYPE config set to? It should be "filesystem".

thadeusb avatar Apr 21 '14 13:04 thadeusb

I suppose it was set to filesystem, but the project has used a different caching mechanism since then.

yaph avatar Apr 21 '14 15:04 yaph

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):

vaamyob avatar Aug 09 '14 14:08 vaamyob

FYI, this is how I'm initializing the cache:

cache = Cache(app=app, config={'CACHE_TYPE': 'FileSystemCache', 'CACHE_DIR': '/tmp'})

vaamyob avatar Aug 09 '14 14:08 vaamyob

Nevermind, I just re-read the docs, I was using FileSystemCache instead of filesystem. All is good now.

vaamyob avatar Aug 09 '14 14:08 vaamyob

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.

thadeusb avatar Aug 09 '14 18:08 thadeusb