Class: Alchemy::Page::SitemapCacheKey
- Inherits:
-
Object
- Object
- Alchemy::Page::SitemapCacheKey
- Defined in:
- app/models/alchemy/page/sitemap_cache_key.rb
Overview
Builds the cache key for the XML sitemap.
The key combines three independent sources of change:
- The contents of the
Alchemy::Page.sitemapscope, as page count and latestupdated_at. - The requested base url (protocol, host and port), because
show_alchemy_page_urlbuilds absolute urls fromrequest.base_urland a site can be served under several of them (seeAlchemy::Site.find_for_host). - A coarse time bucket of
max_ageseconds.
The time bucket is what makes scheduled publishing work. Pages enter and
leave the sitemap when public_on / public_until pass, without any record
being touched, so no content based key can notice that transition. Rotating
the key every max_age seconds bounds how long such a page can be missing.
It also keeps the ETag from freezing: without it, a revalidating client
would receive 304 Not Modified forever.
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#max_age ⇒ Object
readonly
Returns the value of attribute max_age.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #call ⇒ Array<Object>
-
#initialize(site:, base_url:, max_age: Alchemy.config.sitemap.max_age) ⇒ SitemapCacheKey
constructor
A new instance of SitemapCacheKey.
Constructor Details
#initialize(site:, base_url:, max_age: Alchemy.config.sitemap.max_age) ⇒ SitemapCacheKey
Returns a new instance of SitemapCacheKey.
27 28 29 30 31 |
# File 'app/models/alchemy/page/sitemap_cache_key.rb', line 27 def initialize(site:, base_url:, max_age: Alchemy.config.sitemap.max_age) @site = site @base_url = base_url @max_age = max_age end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
22 23 24 |
# File 'app/models/alchemy/page/sitemap_cache_key.rb', line 22 def base_url @base_url end |
#max_age ⇒ Object (readonly)
Returns the value of attribute max_age.
22 23 24 |
# File 'app/models/alchemy/page/sitemap_cache_key.rb', line 22 def max_age @max_age end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
22 23 24 |
# File 'app/models/alchemy/page/sitemap_cache_key.rb', line 22 def site @site end |
Instance Method Details
#call ⇒ Array<Object>
34 35 36 |
# File 'app/models/alchemy/page/sitemap_cache_key.rb', line 34 def call [site&.id, base_url, content_version, time_bucket] end |