Module: CacheAndFetch::Cacheable::ClassMethods

Defined in:
lib/cache_and_fetch/cacheable.rb

Instance Method Summary collapse

Instance Method Details

#cache(p_key) ⇒ Object



42
43
44
45
46
# File 'lib/cache_and_fetch/cacheable.rb', line 42

def cache(p_key)
  resource = find(p_key)
  resource.cache
  resource
end

#cache_clientObject



34
35
36
# File 'lib/cache_and_fetch/cacheable.rb', line 34

def cache_client
  Rails.cache
end

#cache_durationObject



25
26
27
28
# File 'lib/cache_and_fetch/cacheable.rb', line 25

def cache_duration
  self.cache_duration = Cacheable::DEFAULT_CACHE_EXPIRY_TIME unless @cache_duration
  @cache_duration
end

#cache_duration=(val) ⇒ Object



30
31
32
# File 'lib/cache_and_fetch/cacheable.rb', line 30

def cache_duration=(val)
  @cache_duration = val
end

#cache_key(p_key) ⇒ Object



38
39
40
# File 'lib/cache_and_fetch/cacheable.rb', line 38

def cache_key(p_key)
  "#{self.name.underscore}/#{p_key}"
end

#get_cached(p_key) ⇒ Object



48
49
50
# File 'lib/cache_and_fetch/cacheable.rb', line 48

def get_cached(p_key)
  cache_client.read(cache_key(p_key))
end