]> git.openstreetmap.org Git - rails.git/blob - lib/mem_cache.rb
Restriction note deletion to moderators
[rails.git] / lib / mem_cache.rb
1 class MemCache < Memcached::Rails
2   DEFAULT_OPTIONS = Memcached::DEFAULTS.merge(Memcached::Rails::DEFAULTS)
3
4   MemCacheError = Memcached::Error
5
6   @@connections = []
7
8   def initialize(options = {})
9     options.reverse_merge! :namespace_separator => ":"
10
11     super(MEMCACHE_SERVERS, options)
12
13     @@connections.push(self)
14
15     ObjectSpace.define_finalizer(self, lambda { |connection|
16       @@connections.remove(connection)
17     })
18   end
19
20   def self.connections
21     @@connections
22   end
23 end
24
25 if defined?(PhusionPassenger)
26   PhusionPassenger.on_event(:starting_worker_process) do |forked|
27     if forked
28       MemCache.connections.each { |connection| connection.reset }
29     end
30   end
31 end