Method: MemCache#replace

Defined in:
lib/memcache.rb

#replace(key, value, expiry = 0, raw = false) ⇒ Object

Add key to the cache with value value that expires in expiry seconds, but only if key already exists in the cache. If raw is true, value will not be Marshalled.

Raises:



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/memcache.rb', line 460

def replace(key, value, expiry = 0, raw = false)
  raise MemCacheError, "Update of readonly cache" if @readonly
  value = Marshal.dump value unless raw
  with_server(key) do |server, cache_key|
    logger.debug { "replace #{key} to #{server}: #{value ? value.to_s.size : 'nil'}" } if logger
    command = "replace #{cache_key} 0 #{expiry} #{value.to_s.size}#{noreply}\r\n#{value}\r\n"

    with_socket_management(server) do |socket|
      socket.write command
      break nil if @no_reply
      result = socket.gets
      raise_on_error_response! result
      result
    end
  end
end