Amazon S3 cache audio files

Viewed 1460

I have created new music application and I store all mp3 files on Amazon S3. Before moving to S3 I used store them on server file system itself. It used to cache files and on consecutive reload of page files weren't downloaded from server. But after moving to S3 everytime I load page it downloads files from S3. This not only making my app slow but every request to S3 is money. I found some documentation on cache-control and I tried them all but no success. I might be missing something here. Any help is appreciated. Thanks.

Here is my code for uploading mp3 files on S3. I use CarrierWave with Rails.

CarrierWave.configure do |config|
    config.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      =>  MyAppConfig.config['aws']['aws_access_key'],
      :aws_secret_access_key  => MyAppConfig.config['aws']['aws_secret_key'],
    }
    config.fog_directory  = MyAppConfig.config['aws']['aws_bucket_name']
    config.fog_public     = false
    config.storage = :fog
    config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
3 Answers
Related