Module: Cachemere
- Defined in:
- lib/cachemere.rb,
lib/cachemere/version.rb
Constant Summary collapse
- VERSION =
"0.1"
Class Method Summary collapse
- .key_for(param_query) ⇒ Object
-
.start_caching(request, type, controller) ⇒ Object
def self.included(base) base.class_eval do puts “hello” end end.
- .stop_caching(response, expiry = 5) ⇒ Object
Class Method Details
.key_for(param_query) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/cachemere.rb', line 29 def self.key_for param_query pq = param_query if param_query.respond_to? :request pq = param_query.request end "cachemere:#{pq.filtered_parameters["controller"]}:#{pq.filtered_parameters["action"]}:#{Digest::MD5.hexdigest(pq.env["QUERY_STRING"])}" end |
.start_caching(request, type, controller) ⇒ Object
def self.included(base)
base.class_eval do
puts "hello"
end
end
13 14 15 16 17 18 19 20 |
# File 'lib/cachemere.rb', line 13 def self.start_caching request, type, controller puts key = self.key_for(request) cached_value = $redis.get(key) if cached_value controller.headers["X-Cachemere-TTL"] = $redis.ttl(key).to_s controller.render type => cached_value end end |
.stop_caching(response, expiry = 5) ⇒ Object
23 24 25 26 27 |
# File 'lib/cachemere.rb', line 23 def self.stop_caching response, expiry = 5 key = self.key_for(response) $redis.set key, response.body $redis.expire key, expiry end |