Enabling Cache-Control in Amazon S3

Use cache-control request headers in Amazon S3 to avoid repeatedly uploading or serving the same files on a per-bucket basis.

For more information on cache-control options in Amazon S3, see:

http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html#RESTObjectPUT-requests

  1. Login to your Aspera server as root.
    # ssh -i identity_file -p 33001 ec2-user@ec2_host_ip
    #  su -
  2. Create a mapping file to set cache directives.
    The cache-control mapping file is a .txt file that contains the mapping between file extensions and cache directives. The following is sample mapping file content:
    * no-cache
    jpg public
    zip

    These lines set the following directives:

    • * defines a default value, in this case setting cache-control to no-cache for all files
    • files with the .jpg extension have cache-control set to public
    • files ending with .zip have no cache control set

    The file can have any name and be saved in any location. The path to the file is used to configure Trapd, and if the file is saved in /opt/aspera/etc/trapd, then in the next step you need to specify only the file name.

  3. Enable cache-control in Trapd.
    1. Open /opt/aspera/etc/trapd/s3.properties and locate the following section:
      # Path to a file defining a 'Cache-Control' mapping. 
      # The path can be an absolute path otherwise it's the name of a file expected to
      # be in /opt/aspera/etc/trapd.
      # The mapping defines 'Cache-Control' to be used based on the file extension: 
      # - the special extension '*' defines a default value
      # - leaving the cache directive empty means that no 'Control-Cache' would be set.
      # - a line starting with # is a comment and is ignored.
      #
      # Example
      # *   no-cache
      # jpg public
      # zip
      # would by default set a 'Cache-Control' to 'no-cache'
      # files ending with '.jpg' would have 'Cache-Control' set to 'public'
      # files ending with '.zip' would have no 'Cache-Control' set
      # 
      # Default is undefined (no Cache-Control is set)
      #aspera.s3session.cache-control-map=
    2. Uncomment the last line and set the value as the path to your cache-control mapping file.
      The path can be just the name of the file if you have saved it in /opt/aspera/etc/trapd, otherwise enter the full path to the file. For example, if the mapping file, my-cache-control.txt, is in /trapd, then the line is as follows:
      aspera.s3session.cache-control-map=my-cache-control.txt

      If the file has been saved elsewhere, use the full path:

      aspera.s3session.cache-control-map=/user1/s3_settings/my-cache-control.txt
    3. Save your changes.
  4. Restart Trapd to activate your changes.
    # systemctl asperatrapd restart
  5. Perform a test upload and confirm that the cache-control option is set according to the mapping file.