instance method add

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

add(key, value, expiry = 0, raw = false)

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

Readers should call this method in the event of a cache miss, not MemCache#set.

Parameters

key req
value req
expiry opt = 0
raw opt = false
Source
# File activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb, line 393
  def add(key, value, expiry = 0, raw = false)
    raise MemCacheError, "Update of readonly cache" if @readonly
    with_server(key) do |server, cache_key|
      value = Marshal.dump value unless raw
      logger.debug { "add #{key} to #{server}: #{value ? value.to_s.size : 'nil'}" } if logger
      command = "add #{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

Defined in activesupport/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb line 393 · View on GitHub · Improve this page · Find usages on GitHub

Defined in MemCache

Type at least 2 characters to search.

↑↓ navigate · open · esc close