The Couchbase client library has many API methods that you can use to implement whatever you desire. The following tables outline some API categories, the methods that are available, and a short description of what those methods do.
These methods allow all of the operations defined for the
memcached protocol, which is implemented in the Enyim client
library inside the
Enyim.Caching.MemcachedClient class. A few
of these methods have generic versions that allow automatic
type casting of serializable objects to be retrieved. Many of
these methods can also return a Boolean value indicating
whether the operation succeeded or failed.
Append | Append some bytes to the end of a key. |
Decrement | Decrement a key and return the value. |
FlushAll | Flush all data on all servers for the connected bucket. |
Get | Get the value for a key. |
Increment | Increment the value of a key. |
Prepend | Prepend some bytes to the start of a key. |
Remove | Removes a key from the database. |
Stats | Return statistics about a key, or about the servers in the cluster. |
Store | Stores a value for a key. |
TryGet | Tries to get a value, and returns a Boolean if the value was successfully retrieved. |
The MemcachedClient has a number of methods
that allow a Check and Set operation to be performed on keys
in the database. Check and Set operations (CAS) are a way to
prevent data loss in a distributed database without heavy
locks or transactions. Before you write data into the database
you can obtain the current cas value, which
is effectively like a version number for the data in the
database. When you write your new data into the database you
pass along the version you think the data is supposed to have.
If, by the time the write happens, the value is no longer
valid your code will be told that your write failed. You will
then be able to take corrective action such as reading the new
value, its cas, and retrying your operation.
Cas | Perform a Check And Set operation. |
Decrement | Some of the Decrement overloads support returning a
CasResult. |
GetWithCas | Perform a Get and also return a CasResult. |
Increment | Some Increment overloads support passing back a Cas to check for whether the operation succeeded. |
TryGetWithCas | Returns a Boolean so your code knows if the value exists or not, and returns a CasResult if it succeeds. |
The Couchbase library includes the
CouchbaseClient class, which is a subclass
of the MemcachedClient class. It has a set
of methods that provide very powerful ways to interact with
data and extent the expiry time concurrently. You will be able
to use all of these methods (get, touch and CAS equivalents)
on both both Couchbase and Memcached buckets in Couchbase 1.7,
except for the Sync operation. Sync is only supported on
Couchbase buckets.
Get | A special form of Get, sometimes referred to as Get and Touch, which a returns the value but allows the expiry time to be reset. |
GetWithCas | Get a value, its Cas, and also reset the expiry, all at once. |
Sync | A very new operation that allows you to wait for data in the database to change in specific ways. Allows you to know when data has been persisted, replicated, or mutated. Remember this operation can only be performed on Couchbase buckets. |
Touch | Reset a keys expiry date without getting its value. |
TryGet | Try to get a value, a Boolean indicates success, reset the expiry, all at once. |
TryGetWithCas | Swiss army knife. Gets a Boolean indicating if the operation succeeded,
gets a CasResult and also resets
the expiry time of value. |