Module: MethodCachable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Helper
- Defined in:
- lib/method_cachable.rb,
lib/method_cachable/helper.rb,
lib/method_cachable/version.rb
Defined Under Namespace
Modules: ClassMethods, Helper
Constant Summary
collapse
- VERSION =
"0.0.1"
Instance Method Summary
collapse
Methods included from Helper
#createsig, #sigflat
Instance Method Details
#flush_cache(saving_key) ⇒ Object
63
64
65
66
|
# File 'lib/method_cachable.rb', line 63
def flush_cache(saving_key)
lst = Rails.cache.fetch saving_key do; [] end
lst.each {|key| flush_key(key) }
end
|
#flush_key(key) ⇒ Object
68
69
70
|
# File 'lib/method_cachable.rb', line 68
def flush_key(key)
Rails.cache.delete key
end
|
#with_env(key, saving_key = nil, &block) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/method_cachable.rb', line 50
def with_env(key, saving_key = nil, &block)
if Rails.env.production?
unless saving_key.nil?
lst = Rails.cache.fetch saving_key do; [] end
lst << key unless lst.include?(saving_key)
Rails.cache.write saving_key, lst, expires_in: 24.hours
end
Rails.cache.fetch key, expires_in: 2.hours, &block
else
yield
end
end
|