Module: CacheMan::Cacheable

Extended by:
ActiveSupport::Concern
Defined in:
lib/cache_man/cacheable.rb

Defined Under Namespace

Modules: ClassMethods

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.cache_durationObject (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

#cacheObject



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_clientObject



40
41
42
# File 'lib/cache_man/cacheable.rb', line 40

def cache_client
  self.class.cache_client
end

#cache_hard_expires_inObject

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_keyObject



44
45
46
# File 'lib/cache_man/cacheable.rb', line 44

def cache_key
  self.class.cache_key(self.id)
end

#stale?Boolean

Returns:

  • (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