Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Google Cloud Storage: Cache Control #411

Closed
ezarowny opened this issue Oct 23, 2017 · 9 comments
Closed

Google Cloud Storage: Cache Control #411

ezarowny opened this issue Oct 23, 2017 · 9 comments

Comments

@ezarowny
Copy link

It'd be nice to be able set the cache control header at the time of object upload. The docs for this can be found here: https://googlecloudplatform.github.io/google-cloud-python/latest/storage/blobs.html#google.cloud.storage.blob.Blob.cache_control

@gfhuseyinyilmaz
Copy link

Hello, actually this is very important to use google cloud as storage backend. Because google-cdn requires cache-control headers to cache google-cloud-storage files.

@gfhuseyinyilmaz
Copy link

In case anybody else ends up here, to solve this issue I made a custom storage backend with updated _save method like this:

class GoogleCloudStorage(OriginalStorage):

    def _save(self, name, content):
        cleaned_name = clean_name(name)
        name = self._normalize_name(cleaned_name)

        content.name = cleaned_name
        encoded_name = self._encode_name(name)
        file = GoogleCloudFile(encoded_name, 'rw', self)
        # Modification start
        file.blob.cache_control = 'public, max-age=31622400'
        # Modification end
        file.blob.upload_from_file(content, size=content.size,
                                   content_type=file.mime_type)
        return cleaned_name

@ezarowny, thanks for sharing api for this.

@zamai
Copy link

zamai commented Jan 20, 2018

Thanks for sharing, @gfhuseyinyilmaz wouldn't it be nice to have it as a setting? The same way it is for S3?
http://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html?highlight=CacheControl

@cerny-jan
Copy link

Hi, I've opened a PR for this #459

@erikkn
Copy link

erikkn commented Mar 9, 2018

@zamai It would be nice to have it as a setting, but most of the time you want different headers for different type of files, this would be a really nice feature imho.

@noelbautista91
Copy link

Is this project still active? This setting seems like a necessity as not everyone wants no-cache. There seems to be a PR for this with tests failing for some reason.

@jschneier
Copy link
Owner

@nbau21 not as much as it deserves. There is a fair amount of duplicity and technical debt from when I forked it combined with me shifting to freelance has sort of crushed a lot of my time & will. Ideally people who added large backends would be happy to maintain them but I don't think they owe anything to anyone.

Obviously just added in this fix to master. Thanks for the ping.

@noelbautista91
Copy link

Thanks for the response. It's the beauty of open source, anyone can chime in, fork, etc.

Also thanks for merging this to master. I didn't mean to sound entitled in my previous post- I guess I was a bit frustrated at the lack of support for Google Cloud Storage in Django, compared to AWS.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@ezarowny @jschneier @noelbautista91 @zamai @cerny-jan @erikkn @gfhuseyinyilmaz and others