Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.0
Community Wiki and Resources
Wiki: Java Client Library
Download Client Library
JavaDoc
Java Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
7 Retrieve Operations
Chapter Sections
Chapters

7.3. Get-and-Touch Methods

The Get-and-Touch (GAT) methods obtain a value for a given key and update the expiry time for the key. This can be useful for session values and other information where you want to set an expiry time, but don't want the value to expire while the value is still in use.

API Callclient.getAndTouch(key, expiry)
Asynchronousno
Description Get a value and update the expiration time for a given key
Introduced Version1.0
ReturnsCASValue ( Check and set object )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).

The first form of the getAndTouch() obtains a given value and updates the expiry time. For example, to get session data and renew the expiry time to five minutes:

session = client.getAndTouch("sessionid",300);
API Callclient.getAndTouch(key, expiry, transcoder)
Asynchronousno
Description Get a value and update the expiration time for a given key
Introduced Version1.0
ReturnsCASValue ( Check and set object )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form supports the use of a custom transcoder for the stored value information.

API Callclient.asyncGetAndTouch(key, expiry)
Asynchronousyes
Description Get a value and update the expiration time for a given key
Introduced Version1.0
ReturnsFuture<CASValue<Object>> ( Asynchronous request value, as CASValue, as Object )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).

The asynchronous methods obtain the value and update the expiry time without requiring you to actively wait for the response. The returned value is a CAS object with the embedded value object.

Future<CASValue<Object>> future = client.asyncGetAndTouch("sessionid", 300);

CASValue casv;

try {
    casv = future.get(5, TimeUnit.SECONDS);
} catch(Exception e) {
    future.cancel(false);
}
API Callclient.asyncGetAndTouch(key, expiry, transcoder)
Asynchronousyes
Description Get a value and update the expiration time for a given key
Introduced Version1.0
ReturnsFuture<CASValue<T>> ( Asynchronous request value, as CASValue as Transcoded object )
Arguments 
String key Document ID used to identify the value
int expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form of the asynchronous method supports the use of a custom transcoder for the stored object.