instance method write

Ruby on Rails 2.2.3

Since v2.2.3

Available in: v2.2.3 v2.3.18 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

write(key, value, options = nil)

Writes a value to the cache.

Possible options:

  • :unless_exist - set to true if you don’t want to update the cache if the key is already set.

  • :expires_in - the number of seconds that this value may stay in the cache. See ActiveSupport::Cache::Store#write for an example.

Parameters

key req
value req
options opt = nil
Source
# File activesupport/lib/active_support/cache/mem_cache_store.rb, line 58
      def write(key, value, options = nil)
        super
        method = options && options[:unless_exist] ? :add : :set
        # memcache-client will break the connection if you send it an integer
        # in raw mode, so we convert it to a string to be sure it continues working.
        value = value.to_s if raw?(options)
        response = @data.send(method, key, value, expires_in(options), raw?(options))
        response == Response::STORED
      rescue MemCache::MemCacheError => e
        logger.error("MemCacheError (#{e}): #{e.message}")
        false
      end

Defined in activesupport/lib/active_support/cache/mem_cache_store.rb line 58 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Cache::MemCacheStore

Type at least 2 characters to search.

↑↓ navigate · open · esc close