Posts tagged ‘Cloud Files’

Set far-future expires headers with Rackspace Cloud Files (sort of)

To keep parity with existing relationships, a client has required that we work with Cloud Files instead of Amazon’s CloudFront. There seems to be quite a bit of confusion about which offering actually performs better, but from my perspective, the Amazon API is much more intuitive, and therefore easier to work with. That said, there seems to be a lot of misinformation out there about Cloud Files; after spending a day with the API, I am pleased to conclude that the API is not as bad as I had initially thought. Rackspace could likely benefit from a little platform evangelism…

The biggest issue I’ve seen reported from a number of sources is the 72 hour TTL limit via the Rackspace control panel. Cloud Files uses TTL as an expires header of sorts. So I jumped on support chat, and quickly learned that the 72 hour TTL is only a limitation of the control panel, and a far-future TTL can easily be set via the API.

For this particular project, I’m using CakePHP, so don’t get too caught up on that App::import static method. Assuming cloudfiles.php, cloudfiles_exceptions.php, and cloudfiles_http.php are all in a cloudfiles folder in the vendors directory…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function publish(){
    //load up the cloudfiles class
    App::import('Vendor', 'cloudfiles/cloudfiles');

    //create a connection with your Cloud Files username and API secret
    $auth = new CF_Authentication('USER_NAME', 'API_SECRET');
    $auth->authenticate();
    $conn = new CF_Connection($auth);

    //grab an instance of our container
    $container = $conn->get_container('CONTAINER_NAME');

    //get the container's current TTL (assuming this was an existing container)
    debug( $container->cdn_ttl );

    //now just call the make_public method with a TTL parameter
    //here I'm just setting it to 30 days
    $container->make_public(86400 * 30);

    //confirm the TTL was properly updated
    debug( $container->cdn_ttl );
    exit();
}

The script outputs TTL values of 259200 and 2592000 respectively; the TTL on the container is now 30 days instead of 3. I have not noticed the updated TTL on the Rackspace control panel yet, but I’ll update this post if it is accurate once the existing 72 hour TTL expires.