Module: SmartCache
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/smart_cache.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.block_cache(key = nil, ttl = 1.day) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/smart_cache.rb', line 9 def self.block_cache(key=nil, ttl=1.day) results = Rails.cache.read(key) return results if results results = yield Rails.cache.write(key, results, :expires_in => ttl) return results end |
.included(base) ⇒ Object
5 6 7 |
# File 'lib/smart_cache.rb', line 5 def self.included(base) base.after_save :update_caching end |
Instance Method Details
#update_caching ⇒ Object
17 18 19 20 21 |
# File 'lib/smart_cache.rb', line 17 def update_caching cache_key = Digest::MD5.hexdigest("short_cache_by_id_#{self.class.name}_#{self.id}") Rails.cache.write(cache_key, self, :expires_in => eval("#{self.class.name}::EXPIRE_TIME")) return true end |