Sha256: 53450a0ad5c6ab57d66f0eb9b104e66a73803a83a7751de8cc85efe9698fd062
Contents?: true
Size: 985 Bytes
Versions: 9
Compression:
Stored size: 985 Bytes
Contents
# do not let MemCache timeouts kill your app, # mark as error and return read_error_callback (e.g. nil -> cache miss) MemCache # class should exist at this point class MemCache # Add your callback to stop timeouts from raising # # MemCache.read_error_callback = lambda{|error| # error.message << ' -- catched' # HoptoadNotifier.notify error # nil # } class << self attr_accessor :read_error_callback end attr_accessor :read_error_occurred def cache_get_with_timeout_protection(*args) begin @read_error_occurred = false cache_get_without_timeout_protection(*args) rescue Exception => error @read_error_occurred = true if error.to_s == 'IO timeout' and self.class.read_error_callback self.class.read_error_callback.call error else raise error end end end alias_method :cache_get_without_timeout_protection, :cache_get alias_method :cache_get, :cache_get_with_timeout_protection end
Version data entries
9 entries across 9 versions & 1 rubygems