Class: Renalware::Letters::PdfLetterCache
- Inherits:
-
Object
- Object
- Renalware::Letters::PdfLetterCache
- Defined in:
- app/models/renalware/letters/pdf_letter_cache.rb
Class Method Summary collapse
-
.cache_key_for(letter, **options) ⇒ Object
Note the letter must be a LetterPresenter which has a #to_html method The to_html method should (and does on the LetterPresenter class) render the complete html including surrounding layout with inline css and images.
- .cache_path ⇒ Object
- .fetch(letter, **options) ⇒ Object
- .store ⇒ Object
Class Method Details
.cache_key_for(letter, **options) ⇒ Object
Note the letter must be a LetterPresenter which has a #to_html method The to_html method should (and does on the LetterPresenter class) render the complete html including surrounding layout with inline css and images. This way if the layout changes or the image is changed for example, the cache for the pdf is no longer valid and a new key and cache entry will be created.
51 52 53 54 55 56 |
# File 'app/models/renalware/letters/pdf_letter_cache.rb', line 51 def cache_key_for(letter, **) = letter&.updated_at&.strftime("%Y%m%d%H%M%S") pat_id = letter.patient.id "letter-pdf-#{letter.id}-#{pat_id}-#{}-" \ "#{Digest::MD5.hexdigest(letter.to_html(**))}" end |
.cache_path ⇒ Object
58 59 60 |
# File 'app/models/renalware/letters/pdf_letter_cache.rb', line 58 def cache_path Rails.root.join("tmp/pdf_letter_cache") end |
.fetch(letter, **options) ⇒ Object
42 43 44 |
# File 'app/models/renalware/letters/pdf_letter_cache.rb', line 42 def fetch(letter, **) store.fetch(cache_key_for(letter, **)) { yield } end |
.store ⇒ Object
62 63 64 |
# File 'app/models/renalware/letters/pdf_letter_cache.rb', line 62 def store @store ||= ActiveSupport::Cache::FileStore.new(cache_path) end |