You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importhashlibfromdjango.confimportsettingsfromdjango.core.cacheimportcachefromstorages.backends.s3boto3importS3Boto3StorageclassCachedS3Boto3Storage(S3Boto3Storage):
""" adds caching for temporary urls """defurl(self, name):
# Add a prefix to avoid conflicts with any other appskey=hashlib.md5("CachedS3Boto3Storage_%s"%name).hexdigest()
result=cache.get(key)
ifresult:
returnresult# No cached value exists, follow the usual logicresult=super(CachedS3Boto3Storage, self).url(name)
# Cache the result for 3/4 of the temp_url's lifetime.try:
timeout=settings.AWS_QUERYSTRING_EXPIREexcept:
timeout=3600timeout=int(timeout*.75)
cache.set(key, result, timeout)
returnresult
When viewing galleries of files, every page load uses a newly signed URL so it can't be cached. This makes navigating page to page a bit laggier. This storage would return the same signed url for 3/4 of the lifetime of the signature.
The text was updated successfully, but these errors were encountered:
From https://stackoverflow.com/a/42912118:
When viewing galleries of files, every page load uses a newly signed URL so it can't be cached. This makes navigating page to page a bit laggier. This storage would return the same signed url for 3/4 of the lifetime of the signature.
The text was updated successfully, but these errors were encountered: