Class: Dalli::Server
- Inherits:
-
Object
- Object
- Dalli::Server
- Defined in:
- lib/dalli/server.rb
Constant Summary collapse
- DEFAULTS =
{ # seconds between trying to contact a remote server :down_retry_delay => 1, # connect/read/write timeout for socket operations :socket_timeout => 0.5, # times a socket operation may fail before considering the server dead :socket_max_failures => 2, # amount of time to sleep between retries when a failure occurs :socket_failure_delay => 0.01, # max size of value in bytes (default is 1 MB, can be overriden with "memcached -I <size>") :value_max_bytes => 1024 * 1024, # min byte size to attempt compression :compression_min_size => 1024, # max byte size for compression :compression_max_size => false, :username => nil, :password => nil, :keepalive => true }
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
-
#initialize(attribs, options = {}) ⇒ Server
constructor
A new instance of Server.
- #lock! ⇒ Object
-
#request(op, *args) ⇒ Object
Chokepoint method for instrumentation.
- #unlock! ⇒ Object
Constructor Details
#initialize(attribs, options = {}) ⇒ Server
Returns a new instance of Server.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dalli/server.rb', line 31 def initialize(attribs, = {}) (@hostname, @port, @weight) = attribs.split(':') @port ||= 11211 @port = Integer(@port) @weight ||= 1 @weight = Integer(@weight) @fail_count = 0 @down_at = nil @last_down_at = nil @options = DEFAULTS.merge() @sock = nil @msg = nil @pid = nil @inprogress = nil end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/dalli/server.rb', line 6 def hostname @hostname end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/dalli/server.rb', line 9 def @options end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/dalli/server.rb', line 7 def port @port end |
#weight ⇒ Object
Returns the value of attribute weight.
8 9 10 |
# File 'lib/dalli/server.rb', line 8 def weight @weight end |
Instance Method Details
#alive? ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dalli/server.rb', line 70 def alive? return true if @sock if @last_down_at && @last_down_at + [:down_retry_delay] >= Time.now time = @last_down_at + [:down_retry_delay] - Time.now Dalli.logger.debug { "down_retry_delay not reached for #{hostname}:#{port} (%.3f seconds left)" % time } return false end connect !!@sock rescue Dalli::NetworkError false end |
#close ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/dalli/server.rb', line 85 def close return unless @sock @sock.close rescue nil @sock = nil @pid = nil @inprogress = false end |
#lock! ⇒ Object
93 94 |
# File 'lib/dalli/server.rb', line 93 def lock! end |
#request(op, *args) ⇒ Object
Chokepoint method for instrumentation
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dalli/server.rb', line 48 def request(op, *args) verify_state raise Dalli::NetworkError, "#{hostname}:#{port} is down: #{@error} #{@msg}" unless alive? begin send(op, *args) rescue Dalli::NetworkError raise rescue Dalli::MarshalError => ex Dalli.logger.error "Marshalling error for key '#{args.first}': #{ex.}" Dalli.logger.error "You are trying to cache a Ruby object which cannot be serialized to memcached." Dalli.logger.error ex.backtrace.join("\n\t") false rescue Dalli::DalliError raise rescue => ex Dalli.logger.error "Unexpected exception in Dalli: #{ex.class.name}: #{ex.}" Dalli.logger.error "This is a bug in Dalli, please enter an issue in Github if it does not already exist." Dalli.logger.error ex.backtrace.join("\n\t") down! end end |
#unlock! ⇒ Object
96 97 |
# File 'lib/dalli/server.rb', line 96 def unlock! end |