Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i18n] Add locale to cache key - weblab #52067

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dashboard/app/models/levels/weblab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.create_from_level_builder(params, level_params)

# Return an 'appOptions' hash derived from the level contents
def non_blockly_puzzle_level_options
options = Rails.cache.fetch("#{cache_key}/non_blockly_puzzle_level_options/v2") do
options = Rails.cache.fetch("#{cache_key}/#{I18n.locale}/non_blockly_puzzle_level_options/v2") do
level_prop = {}

properties.keys.each do |dashboard|
Expand Down
46 changes: 31 additions & 15 deletions lib/cdo/http_cache.rb
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are only line-length changes within the comments at the top of the file (cause Dayne pointed me here but it was really hard to read the comment).

Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
# HTTP Cache configuration.
#

# Provides application-specific cache configuration used by all our various
# HTTP cache layers.
#

# Note that this implementation does include some Varnish-specific logic; we no
# longer use Varnish and so no longer rely on that logic. We could consider
# removing our support for Varnish and simplifying this implementation.
#

# `pegasus` and `dashboard` keys each return a Hash in the following format:
#
# - `behaviors`: Array of behaviors. For a given HTTP request, `behaviors` is searched in-order until the first matching `path` is found. If no `path` matches the request, the `default` behavior is used.
# - `path`: Path string to match this behavior against. A single `*`-wildcard is required, either an extension-wildcard `/*.jpg` or path-wildcard `/api/*`.
# - `path` can be a String or an Array. If it is an Array, a separate behavior will be generated for each element.
# - Paths match the CloudFront [path pattern](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern) syntax, with additional restrictions:

# - `behaviors`: Array of behaviors. For a given HTTP request, `behaviors` is searched
# in-order until the first matching `path` is found. If no `path` matches the
# request, the `default` behavior is used.
# - `path`: Path string to match this behavior against. A single `*`-wildcard is
# required, either an extension-wildcard `/*.jpg` or path-wildcard `/api/*`.
# - `path` can be a String or an Array. If it is an Array, a separate behavior will
# be generated for each element.
# - Paths match the CloudFront
# [path pattern](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern)
# syntax, with additional restrictions:
# - `?` and `&` characters are not allowed.
# - Only a single `*` wildcard is allowed at the start or end of the path pattern.
# - `headers` (CloudFront-only): Cache objects based on additional HTTP request headers. To include all headers (which disables caching entirely for the path), pass `['*']`. To include no additional request headers in the cache key, pass `[]`.
# - `headers` (CloudFront-only): Cache objects based on additional HTTP request headers.
# To include all headers (which disables caching entirely for the path), pass `['*']`.
# To include no additional request headers in the cache key, pass `[]`.
# - Note: Objects are already cached based on the `Host` header by default.
# - Note: `headers` is currently only used by CloudFront, while Varnish caches objects based on the `Vary` HTTP response header.
# - Note: `headers` is currently only used by CloudFront, while Varnish caches objects
# based on the `Vary` HTTP response header.
# - `query`: (boolean) Forward query strings to the origin. (default `true`)
# - `cookies`: An allowlist array of HTTP cookie keys to pass to the origin and include in the cache key. To allowlist all cookies for the path, pass `'all'`. To strip all cookies for the path, pass `'none'`.
# - `proxy` (Varnish-only): If specified, proxy all requests matching this path to the specified origin. (Currently either `'dashboard'` or `'pegasus'`)
# - Note: paths are not rewritten, so e.g., a GET request to `server1.code.org/here/abc` configured with the behavior `{path: '/here/*' proxy: 'dashboard' }` will proxy its request to `server1-studio.code.org/here/abc`.
# - Note: `proxy` is not yet implemented in CloudFront. (Proxies will still work correctly when passed through to Varnish.)
# - `default`: Default behavior if no other path patterns are matched. Uses the same syntax as `behaviors` except `path` is not required.
# - `cookies`: An allowlist array of HTTP cookie keys to pass to the origin and include
# in the cache key. To allowlist all cookies for the path, pass `'all'`. To strip all
# cookies for the path, pass `'none'`.
# - `proxy` (Varnish-only): If specified, proxy all requests matching this path to the
# specified origin. (Currently either `'dashboard'` or `'pegasus'`)
# - Note: paths are not rewritten, so e.g., a GET request to `server1.code.org/here/abc`
# configured with the behavior `{path: '/here/*' proxy: 'dashboard' }` will proxy its
# request to `server1-studio.code.org/here/abc`.
# - Note: `proxy` is not yet implemented in CloudFront. (Proxies will still work correctly
# when passed through to Varnish.)
# - `default`: Default behavior if no other path patterns are matched. Uses the same syntax
# as `behaviors` except `path` is not required.
class HttpCache
# Paths for files that are always cached based on their extension.
STATIC_ASSET_EXTENSION_PATHS = %w(css js mp3 jpg png).map {|ext| "/*.#{ext}"}.freeze
Expand Down