-import os
-from django.core.cache.backends.filebased import FileBasedCache
-
-
-class StaticFileBasedCache(FileBasedCache):
- def __init__(self, *args, **kwargs):
- super(StaticFileBasedCache, self).__init__(*args, **kwargs)
- self._dir = os.path.abspath(self._dir)
-
- def make_key(self, key, version=None):
- assert version is None, \
- 'StaticFileBasedCache does not support versioning.'
- return key
-
- def _key_to_file(self, key):
- key = os.path.abspath(os.path.join(self._dir, key.lstrip('/')))
- assert key.startswith(self._dir), 'Trying to save path outside root.'
- if key.endswith('/'):
- key += 'index.html'
- return key
-
- def get(self, key, default=None, version=None):
- key = self.make_key(key, version=version)
- self.validate_key(key)
- fname = self._key_to_file(key)
- try:
- with open(fname, 'rb') as inf:
- return inf.read()
- except (IOError, OSError):
- pass
- return default
-
- def set(self, key, value, timeout=None, version=None):
- assert timeout is None, \
- 'StaticFileBasedCache does not support timeouts.'
- key = self.make_key(key, version=version)
- self.validate_key(key)
- fname = self._key_to_file(key)
- dirname = os.path.dirname(fname)
+from django.core.cache import InvalidCacheBackendError
+from .conf import conf
+
+
+DEFAULT_TIMEOUT = object()
+
+
+try:
+ from django.core.cache import caches
+except ImportError:
+ from django.core.cache import get_cache
+else:
+ get_cache = lambda alias: caches[alias]
+
+
+def get_caches():
+ try:
+ return [get_cache(c) for c in conf.CACHE_ALIASES]
+ except: