module ContentfulRails::Caching::Timestamps
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. Also includes a module method to remove an existing timestamp.
Public Class Methods
prepended(base)
click to toggle source
@private
# File lib/contentful_rails/caching/timestamps.rb, line 9 def self.prepended(base) base.extend ClassMethods end
Public Instance Methods
cache_key()
click to toggle source
Get the cache key
Calls superclass method
# File lib/contentful_rails/caching/timestamps.rb, line 46 def cache_key if ContentfulModel.use_preview_api "preview/#{super}" else super end end
timestamp_cache_key()
click to toggle source
Get the cache key for the timestamp for the current object
# File lib/contentful_rails/caching/timestamps.rb, line 30 def timestamp_cache_key self.class.timestamp_cache_key(id) end
updated_at()
click to toggle source
Fetches updated_at
from cache if set, otherwise calls contentful object
Calls superclass method
# File lib/contentful_rails/caching/timestamps.rb, line 35 def updated_at if ContentfulRails.configuration.perform_caching && !ContentfulModel.use_preview_api Rails.cache.fetch(timestamp_cache_key) do super end else super end end