Module: CacheMachine::Cache::ClassMethods
- Defined in:
- lib/cache_machine/cache.rb
Instance Method Summary collapse
-
#acts_as_cache_machine_for(*associations) ⇒ Object
(also: #cache_map)
Initializes tracking associations to write and reset cache.
-
#reset_timestamp(format = nil) ⇒ Object
Resets timestamp of class collection.
-
#reset_timestamps ⇒ Object
Resets all timestams for all formats.
-
#timestamp(format = nil) ⇒ String
Returns timestamp of class collection.
-
#timestamp_key(format = nil) ⇒ String
Returns cache key to fetch timestamp from memcached.
-
#timestamped_key(format = nil) ⇒ String
Returns cache key of anything with timestamp attached.
Instance Method Details
#acts_as_cache_machine_for(*associations) ⇒ Object Also known as: cache_map
Initializes tracking associations to write and reset cache.
60 61 62 63 64 65 |
# File 'lib/cache_machine/cache.rb', line 60 def acts_as_cache_machine_for *associations Time.zone ||= ActiveSupport::TimeZone[0] include CacheMachine::Cache::Map cache_associated(associations) end |
#reset_timestamp(format = nil) ⇒ Object
Resets timestamp of class collection.
104 105 106 107 108 |
# File 'lib/cache_machine/cache.rb', line 104 def format = nil cache_key = format CacheMachine::Logger.info "CACHE_MACHINE (reset_timestamp): deleting '#{cache_key}'." Rails.cache.delete(cache_key) end |
#reset_timestamps ⇒ Object
Resets all timestams for all formats.
111 112 113 |
# File 'lib/cache_machine/cache.rb', line 111 def CacheMachine::Cache.formats.each { |format| format } end |
#timestamp(format = nil) ⇒ String
Returns timestamp of class collection.
76 77 78 |
# File 'lib/cache_machine/cache.rb', line 76 def format = nil Rails.cache.fetch( format) { Time.now.to_i.to_s } end |
#timestamp_key(format = nil) ⇒ String
Returns cache key to fetch timestamp from memcached.
85 86 87 |
# File 'lib/cache_machine/cache.rb', line 85 def format = nil [self.name, format, 'timestamp'].join '_' end |
#timestamped_key(format = nil) ⇒ String
Returns cache key of anything with timestamp attached.
97 98 99 |
# File 'lib/cache_machine/cache.rb', line 97 def format = nil [(format), (format)].join '_' end |