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, or its PDF is
replaced, those fragments keep rendering the OLD version until their TTL
expires. This handler purges the edge cache of every product page that
surfaces the publication so the change shows immediately — no manual purge.
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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/subscribers/publication/cache_purge_handler.rb', line 21 def perform(event) publication = Item.find_by(id: event.data[:item_id]) return unless publication&.is_publication? return unless Cache::EdgeCacheUtility.edge_cache_enabled? urls = publication.publication_edge_cache_urls( previous_product_line_id: event.data[:previous_primary_product_line_id] ) return if urls.blank? Rails.logger.info( "[Publication::CachePurgeHandler] Publication #{publication.id}: purging #{urls.size} edge URL(s)" ) EdgeCacheWorker.perform_async('urls' => urls) rescue StandardError => e ErrorReporting.error(e) raise end |