public Method

MemCache.set(key, value, expiry = 0, raw = false)

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

Warning: Readers should not call this method in the event of a cache miss; see MemCache#add.

Source Code

# File active_support/vendor/memcache-client-1.5.0/memcache.rb, line 322
def set(key, value, expiry = 0, raw = false)
  raise MemCacheError, "Update of readonly cache" if @readonly
  server, cache_key = request_setup key
  socket = server.socket

  value = Marshal.dump value unless raw
  command = "set #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n"

  begin
    @mutex.lock if @multithread
    socket.write command
    result = socket.gets
    raise_on_error_response! result
    result
  rescue SocketError, SystemCallError, IOError => err
    server.close
    raise MemCacheError, err.message
  ensure
    @mutex.unlock if @multithread
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.