1. Alan Justino
  2. django-storages


Alan Justino  committed 1954fcf

FileCache implements .path() if _cache_storage implements it

.path() transfers from _master_storage to _cache_storage if not
already there, than tries _cache_storage.path() and let raise,
as I have no way to know if _cache_storage implements it before

(btw, it works without transfer if _master_storage have .path())

  • Participants
  • Parent commits 670df49
  • Branches default

Comments (0)

Files changed (1)

File storages/backends/filecache.py

View file
  • Ignore whitespace
         return name
+    def path(self, name):
+        """
+        Returns a local filesystem path where the file can be retrieved.
+        If cache_storage is path"able", tranfers from master_storage and serves
+        from cache_storage.
+        :param name: file name
+        :type name: str
+        :rtype: str
+        """
+        try:
+            return self._get_storage(name).path(name)
+        except NotImplementedError, e:
+            if self.using_cache(name):
+                raise
+            else: # Maybe is worth to try with cache_storage if master failed
+                self._transfer(name, origin=self.master_storage, destiny=self.cache_storage)
+                return self.cache_storage.path(name)
 class FileSystemCachedS3BotoStorage(FileCacheMixin, Storage):
     """Caches S3 files on local filesystem.