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 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴