Module: CacheMan::Cacheable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cache_man/cacheable.rb
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.cache_duration ⇒ Object
readonly
Returns the value of attribute cache_duration.
Instance Method Summary collapse
- #cache ⇒ Object
- #cache_client ⇒ Object
-
#cache_hard_expires_in ⇒ Object
this is meant to be overriden to change the expiry (at least for now).
- #cache_key ⇒ Object
- #stale? ⇒ Boolean
Class Attribute Details
.cache_duration ⇒ Object (readonly)
Returns the value of attribute cache_duration.
16 17 18 |
# File 'lib/cache_man/cacheable.rb', line 16 def cache_duration @cache_duration end |
Instance Method Details
#cache ⇒ Object
53 54 55 56 |
# File 'lib/cache_man/cacheable.rb', line 53 def cache @cache_expires_at = Cacheable.cache_duration.since.to_i self.cache_client.write(self.cache_key, self, expires_in: cache_hard_expires_in) end |
#cache_client ⇒ Object
40 41 42 |
# File 'lib/cache_man/cacheable.rb', line 40 def cache_client self.class.cache_client end |
#cache_hard_expires_in ⇒ Object
this is meant to be overriden to change the expiry (at least for now)
49 50 51 |
# File 'lib/cache_man/cacheable.rb', line 49 def cache_hard_expires_in 1.day end |
#cache_key ⇒ Object
44 45 46 |
# File 'lib/cache_man/cacheable.rb', line 44 def cache_key self.class.cache_key(self.id) end |
#stale? ⇒ Boolean
58 59 60 |
# File 'lib/cache_man/cacheable.rb', line 58 def stale? @cache_expires_at && Time.now > Time.at(@cache_expires_at) end |