2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/radiant_tools/redis_radiant_store.rb', line 2
def self.init
Rack::Cache::MetaStore.class_eval do
def marshalable?(value)
begin
Marshal.dump(value)
rescue TypeError
false
end
end
def persist_request(request)
env = request.env.dup
env.reject! { |key,val| (key =~ /[^0-9A-Z_]/) || !marshalable?(val) }
env
end
end
require 'redis-store' unless defined?(Rack::Cache::MetaStore::Redis)
[Rack::Cache::MetaStore::Redis, Rack::Cache::EntityStore::Redis].each do |klass|
klass.class_eval do
def initialize(server, options = {})
@cache = ::Redis::Factory.create server
store = self.class.parent.to_s.underscore.split("/").last.pluralize
(Radiant::Cache.send store) << self
end
def clear(matcher='*')
cache.keys(matcher).each { |key| cache.del key }
end
end
end
end
|