【问题标题】:ActiveStorage Caching Setting - Rails + Google CloudActiveStorage 缓存设置 - Rails + Google Cloud
【发布时间】:2019-07-04 14:12:56
【问题描述】:

我正在尝试使用谷歌云为存储在 Active Storage 中的图像设置缓存。我有以下配置文件

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

production:
  service: GCS
  credentials: <%= Rails.root.join("cert/gcs-production.json") %>
  project: 'my-app-121212'
  bucket: 'my-prod-bucket'

staging:
  service: GCS
  credentials: <%= Rails.root.join("cert/gcs-staging.json") %>
  project: 'my-app-121212'
  bucket: 'my-stage-bucket'

谁能建议我在哪里可以指定缓存设置,我希望缓存图像。

【问题讨论】:

    标签: ruby-on-rails google-cloud-storage rails-activestorage


    【解决方案1】:

    您可以在服务上设置public: true。这将指示 rails 使用来自 GCS 的公共 url,默认情况下将添加缓存标头。请参考official guide

    确保您的 GCS 存储桶已添加公共权限(allUsers 具有查看者角色)

    【讨论】:

      【解决方案2】:

      如果您使用的是 App Engine Flexible 而不是 Compute Engine,则在使用 Google Cloud Storage 时默认允许缓存公开可读对象的文件,由您使用的 service: GCS 标志指示,这意味着您不必指定任何特殊配置。

      请记住,您可以缓存的对象必须是静态文件,例如图像、样式表、JavaScript 等。

      如果您想了解更多关于使用 Rails 从 App Engine 提供静态文件的信息,可以阅读此article from Google Cloud

      【讨论】:

        猜你喜欢
        • 2018-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-03
        • 1970-01-01
        • 2018-07-31
        • 2019-04-13
        相关资源
        最近更新 更多