doujieyu7062 2015-01-29 10:05 采纳率: 0%
浏览 33
已采纳

没有缓存的Google云端存储公共访问

I created a website on Google-Appengine. To reduce the costs of Google-Cloud-SQL my API generates public json-files from Cloud-SQL in my Google-Cloud-Storage that should be read by my Android-App and my Website (via ajax).

The Problem is, that the files of Google-Cloud-Storage are automatically cached for an hour, but I want to disable caching for specific files.

If I upload a file manual in the Developers Console I may change this behaviour with a click on "Edit Metadata" and setting Cache-Control to private, max-age=0,no-transform (see the following picture). Then if I try to access this file, I get the wanted header private, max-age=0,no-transform [Edit Metadata manual

But in my application the json-files are generated by PHP and I always get the header cache-control → public, max-age=3600. I create the files with the following code (Here is the official docs: Docs):

$options = ['gs' => [
    'Content-Type' => 'text/json',
    'acl' => 'public-read',
    'enable_cache' => false,
    'read_cache_expiry_seconds' => 0]
];
$ctx = stream_context_create($options);
file_put_contents($url,$content,0,$ctx);

Has anybody an idea why caching is not turned off?

  • 写回答

1条回答 默认 最新

  • duanping6698 2015-01-30 17:59
    关注

    Mentioned in a related question, you may need to set Cache-Control explicitly/separately in addition to enable_cache and read_cache_expiry_seconds; in particular, the options you are setting control the App Engine side of caching into memcache, whereas the Cache-Control setting is specific to Google Cloud Storage itself. So you want:

    $options = ['gs' => [
        'Content-Type' => 'text/json',
        'acl' => 'public-read',
        'enable_cache' => false,
        'read_cache_expiry_seconds' => 0,
        'Cache-Control' => 'private, max-age=0,no-transform']
    ];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?