Class: Publication::CachePurgeHandler
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Publication::CachePurgeHandler
- Includes:
- RailsEventStore::AsyncHandler
- Defined in:
- app/subscribers/publication/cache_purge_handler.rb
Overview
Async RES handler for Events::PublicationUpdated.
A product page surfaces a publication (the Sell Sheet, Install Guide, …) in its
Documents tab, which Cloudflare caches as a SEPARATE edge entry from the page
URL. So when a publication is revised, discontinued, renamed, its cover is
swapped, or its PDF is replaced, those fragments keep rendering the OLD version
until their TTL expires. This handler purges every page that surfaces the
publication, plus the ImageKit copy of its cover, so the change shows
immediately — no manual purge. Item#purge_publication_cache is the shared
implementation, so the CRM "Purge Cache" button invalidates the same set.
Subscribed in config/initializers/event_store.rb. Runs async (ApplicationJob)
so it fires after the publication's transaction commits and its
publication_items links are persisted (publication_edge_cache_urls reads
them). The actual Cloudflare calls are batched by EdgeCacheWorker.
Instance Method Summary collapse
Instance Method Details
#perform(event) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/subscribers/publication/cache_purge_handler.rb', line 23 def perform(event) publication = Item.find_by(id: event.data[:item_id]) return unless publication&.is_publication? urls = publication.purge_publication_cache( previous_product_line_id: event.data[:previous_primary_product_line_id], previous_page_paths: event.data[:previous_page_paths] ) return unless urls.is_a?(Array) Rails.logger.info( "[Publication::CachePurgeHandler] Publication #{publication.id}: purging #{urls.size} edge URL(s)" ) rescue StandardError => e ErrorReporting.error(e) raise end |