X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/af13c423221bec074e8f17bf0cc77ecc9e0c98c6..f778b61c0358ad2d0593be4040406a418ae46579:/lib/mem_cache.rb diff --git a/lib/mem_cache.rb b/lib/mem_cache.rb new file mode 100644 index 000000000..269b0c3d6 --- /dev/null +++ b/lib/mem_cache.rb @@ -0,0 +1,31 @@ +class MemCache < Memcached::Rails + DEFAULT_OPTIONS = Memcached::DEFAULTS.merge(Memcached::Rails::DEFAULTS) + + MemCacheError = Memcached::Error + + @@connections = [] + + def initialize(options = {}) + options.reverse_merge! :binary_protocol => true, :namespace_separator => ":" + + super(MEMCACHE_SERVERS, options) + + @@connections.push(self) + + ObjectSpace.define_finalizer(self, lambda { |connection| + @@connections.remove(connection) + }) + end + + def self.connections + @@connections + end +end + +if defined?(PhusionPassenger) + PhusionPassenger.on_event(:starting_worker_process) do |forked| + if forked + MemCache.connections.each { |connection| connection.reset } + end + end +end