ActiveStorage 缓存设置 - Rails + Google Cloud

3

我正在尝试为存储在谷歌云的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'

请问在哪里可以指定缓存设置,我想将图片缓存。

最初的回答:

2个回答

1

您可以在服务上设置 public: true。这将指示Rails使用GCS的公共URL,默认情况下会添加缓存头信息。请参考官方指南

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


-1

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

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接