Method: MemCache#set
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb
#set(key, value, expiry = 0, raw = false) ⇒ Object
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.
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/vendor/memcache-client-1.5.1/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. ensure @mutex.unlock if @multithread end end |