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']
    ];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python使用pulp线性优化时报错
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真
  • ¥15 关于IMageEnView 图标定位问题
  • ¥20 求解答(matlab)
  • ¥30 ffmpeg库使用过程中遇到的问题
  • ¥15 pyqt5 中python如何通过Qtwebchannel主动发消息给web前端
  • ¥15 关于HTML中title获取xml内容的问题