1. Marco Pensallorto
  2. django-storages

Commits

Davide Setti  committed c1d3704

cache container_url in the mosso (cloudfiles) backend

  • Participants
  • Parent commits 86505da
  • Branches default

Comments (0)

Files changed (1)

File storages/backends/mosso.py

View file
 from django.core.files import File
 from django.core.files.storage import Storage
 from django.utils.text import get_valid_filename
+from django.core.cache import cache
 
 try:
     import cloudfiles
         self.connection_kwargs = connection_kwargs
         self.serve_https = serve_https
 
+        self.cache_key = "storages:mosso:%(username)s:%(container)s" % dict(
+            username=username, container=container
+        )
+
     def __getstate__(self):
         """
         Return a picklable representation of the storage.
             container.make_public()
         if hasattr(self, '_container_public_uri'):
             delattr(self, '_container_public_uri')
+        cache.delete(self.cache_key)
         self._container = container
 
     container = property(_get_container, _set_container)
 
     def _get_container_url(self):
         if not hasattr(self, '_container_public_uri'):
+
+            cached = cache.get(self.cache_key)
+            if cached:
+                return cached
             if not self.serve_https:
                 self._container_public_uri = self.container.public_uri()
             else:
                 self._container_public_uri = self.container.public_ssl_uri()
+            cache.set(self.cache_key, self._container_public_uri)
         return self._container_public_uri
 
     container_url = property(_get_container_url)