Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library Ruby 1.0
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
7 Ruby — Update Operations
Chapter Sections
Chapters

7.7. Touch Methods

The touch methods allow you to update the expiration time on a given key. This can be useful for situations where you want to prevent an item from expiring without resetting the associated value. For example, for a session database you might want to keep the session alive in the database each time the user accesses a web page without explicitly updating the session value, keeping the user's session active and available.

In Ruby, touch can be used to update or more keys.

API Callobject.touch-one(key [, ruby-touch-options ] [, ruby-touch-keys ])
Asynchronousno
Description Update the expiry time of an item
ReturnsBoolean ( Boolean (true/false) )
Arguments 
string key Document ID used to identify the value
hash ruby-touch-options Hash of options containing key/value pairs
 Structure definition:
 :ttl (fixnum) :ttl  
  Expiration time for record. Default is indefinite, meaning the record will remain until an explicit delete command is made. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
hash ruby-touch-keys Hash of options containing key/value pairs

The following examples demonstrate use of touch with a single key:

#update record so no expiration (record held indefinitely long)

c.touch("foo")

#update expiration to 10 seconds

c.touch("foo", :ttl => 10)

#alternate syntax for updating single value

c.touch("foo" => 10)
API Callobject.touch-many(keyn)
Asynchronousno
Description Update the expiry time of an item
Returnshash ( Container with key/value pairs )
Arguments 
String/Symbol/Array/Hash keyn One or more keys used to reference a value
 Structure definition:
 key (string) Key  
  Key as string.
 keys (strings) Keys  
  Comma-separated strings for each key, e.g. client.get( "foo", "bar")
 symbol (symbol) Symbol  
  Symbol for each key to be retrieved, e.g. :foo.
 hash (hash) Hash Key  
  Key-expiration pairs provided in a hash-map, e.g. c.get("foo" => 10, "bar" => 20) . Returns has of key-values for given keys.

The following examples demonstrate use of touch with multiple keys, which are provided as a hash:

#update two records with 10 and 20 second expirations
#returns hash with key and success/fail
#{"foo" => true, "bar" => true}

c.touch("foo" => 10, :bar => 20)

#Update several values in asynchronous mode
c.run do
      c.touch("foo" => 10, :bar => 20) do |ret|
          ret.operation   #=> :touch
          ret.success?    #=> true
          ret.key         #=> "foo" and "bar" in separate calls
      end
end