Module: ContentfulRails::CachedTimestamps
- Defined in:
- lib/contentful_rails/cached_timestamps.rb
Overview
A module to prepend into ContentfulModel::Base which will allow the model instance to check the cache for its timestamp before making an expensive API call
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 |
# File 'lib/contentful_rails/cached_timestamps.rb', line 5 def self.included(base) base.class_eval do alias_method_chain :updated_at, :caching end end |
Instance Method Details
#timestamp_cache_key ⇒ Object
17 18 19 |
# File 'lib/contentful_rails/cached_timestamps.rb', line 17 def "contentful_timestamp/#{self.class.content_type_id}/#{self.id}" end |
#updated_at_with_caching ⇒ Object
11 12 13 14 15 |
# File 'lib/contentful_rails/cached_timestamps.rb', line 11 def updated_at_with_caching Rails.cache.fetch(self.) do updated_at_without_caching end end |