Skip to content

Commit 671ad91

Browse files
authored
Merge pull request #176 from johaven/master
uWSGI: Check cache is enabled before use it & fix docstring
2 parents e81c0b9 + 1df4652 commit 671ad91

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

flask_caching/backends/uwsgicache.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class UWSGICache(BaseCache):
2929
:param default_timeout: The default timeout in seconds.
3030
:param cache: The name of the caching instance to connect to, for
3131
example: mycache@localhost:3031, defaults to an empty string, which
32-
means uWSGI will cache in the local instance. If the cache is in the
33-
same instance as the werkzeug app, you only have to provide the name of
34-
the cache.
32+
means uWSGI will use the first cache instance initialized.
33+
If the cache is in the same instance as the werkzeug app,
34+
you only have to provide the name of the cache.
3535
"""
3636

3737
def __init__(self, default_timeout=300, cache=""):
@@ -45,13 +45,17 @@ def __init__(self, default_timeout=300, cache=""):
4545

4646
try:
4747
import uwsgi
48-
4948
self._uwsgi = uwsgi
5049
except ImportError:
5150
raise RuntimeError(
52-
"uWSGI could not be imported, are you " "running under uWSGI?"
51+
"uWSGI could not be imported, are you running under uWSGI?"
5352
)
5453

54+
if 'cache2' not in uwsgi.opt:
55+
raise RuntimeError(
56+
"You must enable cache2 in uWSGI configuration: "
57+
"https://uwsgi-docs.readthedocs.io/en/latest/Caching.html")
58+
5559
self.cache = cache
5660

5761
def get(self, key):

0 commit comments

Comments
 (0)