Module: Models::EdgeCachePurgeable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Article, CatalogItem, DigitalAsset, FloorPlanDisplay, Item, ProductLine, Showcase, SiteMap
- Defined in:
- app/concerns/models/edge_cache_purgeable.rb
Overview
Concern for models whose pages are cached at the Cloudflare edge and need
explicit purging when the underlying record changes. Ten models share this
polymorphic interface — controllers, subscribers, services, and rake tasks
call #purge_edge_cache on heterogeneous resources without knowing the
concrete type.
The URL-collection strategy varies per model (site_maps, descendants,
section_cache_urls, route helpers, tag pages, …), but the enqueue mechanism
is identical. This concern provides the shared mechanism and a sensible
default; models with custom collection or cascade logic override
#purge_edge_cache and delegate the enqueue to #enqueue_edge_cache_purge.
Instance Method Summary collapse
-
#edge_cache_urls ⇒ Array<String>
URLs whose edge-cache entries should be purged when this record changes.
-
#enqueue_edge_cache_purge(urls) ⇒ void
Enqueue an EdgeCacheWorker job to purge the given URLs from the Cloudflare edge cache.
-
#purge_edge_cache ⇒ Array<String>
Purge this record's URLs from the edge cache.
Instance Method Details
#edge_cache_urls ⇒ Array<String>
URLs whose edge-cache entries should be purged when this record changes.
The default collects URLs from the site_maps association. Override in
models that need a custom URL set (e.g. Item uses all_site_maps +
section_cache_urls, ProductLine spreads across self_and_descendants).
65 66 67 |
# File 'app/concerns/models/edge_cache_purgeable.rb', line 65 def edge_cache_urls site_maps.map(&:url) end |
#enqueue_edge_cache_purge(urls) ⇒ void
This method returns an undefined value.
Enqueue an EdgeCacheWorker job to purge the given URLs from the
Cloudflare edge cache. This is the shared mechanism behind every
model's #purge_edge_cache — the URL-collection strategy varies per
model, but the enqueue is identical.
55 56 57 |
# File 'app/concerns/models/edge_cache_purgeable.rb', line 55 def enqueue_edge_cache_purge(urls) EdgeCacheWorker.perform_async('urls' => urls) if urls.present? end |
#purge_edge_cache ⇒ Array<String>
Purge this record's URLs from the edge cache. The default implementation
collects #edge_cache_urls and enqueues a single EdgeCacheWorker job.
Models with cascade, route-building, or enabled-check requirements
override this method and delegate the enqueue to
#enqueue_edge_cache_purge.
76 77 78 79 80 |
# File 'app/concerns/models/edge_cache_purgeable.rb', line 76 def purge_edge_cache urls = edge_cache_urls enqueue_edge_cache_purge(urls) urls end |