【问题标题】:How to set Cache control for external cloud files如何为外部云文件设置缓存控制
【发布时间】:2010-09-27 14:36:15
【问题描述】:

大家好, 我一心想提高我的页面速度因素,昨天我在 rackspacecloud 上获得了一些云空间。现在在此之前,我通过 htaccess 提供来自无 cookie 域的静态内容,并具有适当的缓存控制。

现在,在我转到云之后,我的 htaccess 不再控制云文件。 rackspace 上有一个 TTL 参数,用于设置文件应在 CDN 上保留多长时间的值。该值反映在我的页面速度设置(google + firebug)上。现在默认设置最多可以 72 小时,但我需要 7 天以上的时间。我需要一些 api 和它有点复杂..

有什么方法可以对我的云文件实施缓存控制? 这些查询字符串是做什么的 domain.com/file.css?cache=0.54454334 ???

他们实现了我的目标吗? 任何帮助表示赞赏。

【问题讨论】:

    标签: php caching controls performance


    【解决方案1】:

    您可能已经知道了,但这里有一个结帐链接:Set far-future expires headers with Rackspace Cloud Files (sort of)

    他正在使用cloudfiles PHP API,我也是。您可以手动将 TTL(又名过期)标头设置为您想要的任何内容。现在我将它们设置为 365 天(可能有点过分)。

    文档相当简单。如果您需要任何帮助,此代码应该可以帮助您入门:

    <?php
    
    // include the API
    require('cloudfiles.php');
    
    // cloud info
    $username = "myusername"; // username
    $key = "c2dfa30bf91f345cf01cb26d8d5ea821"; // api key
    
    // Connect to Rackspace
    $auth = new CF_Authentication($username, $key);
    $auth->authenticate();
    $conn = new CF_Connection($auth);
    
    // Get the container we want to use
    $container = $conn->create_container('images');
    
    // store file information
    $filename  = "images/logo.jpg";
    
    // upload file to Rackspace
    $object = $container->create_object($filename);
    $object->load_from_filename($localfile);
    
    // make public, and set headers
    $container->make_public(86400 * 365); // expires headers set to 365 days
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 2019-01-14
      • 2017-06-19
      • 2016-01-04
      • 2016-05-30
      • 2019-10-06
      相关资源
      最近更新 更多