When you store a key-document pair in Couchbase Server, it also saves meta data that is associated with the new record. The following are the types of meta data:
Expiration, also known as Time to Live, or TTL.
Check and Set value (CAS), which is often also called a Compare and Swap value.
Flags, which are typically SDK-specific and are often used to identify the type of data stored, or to specify formatting.
Couchbase Server also stores metadata that will not be visible to you, but is used internally by the server to track keys and internally manage documents.
CAS values enable you to store information and then require that
a client provide the correct unique CAS value in order to update
it. Be aware that performing a function with CAS does slow
storing or retrieval. There are some operations that should be
fast in nature where you do not want to perform with CAS, for
instance append(). For some SDKs a CAS
value is nonetheless required to perform the operation. In this
case, you can provide 0 as the CAS and the operation will
execute without comparing the CAS value. For more information,
see "Using Couchbase SDKs."
Flags are used by SDKs to perform a variety of information- and SDK-specifc function. Typically a Couchbase SDK will use a flag to determine if information should be serialized or formatted in a particular way. For instance, in the case of Java, a flag can signify the data type of an object you are storing. Some SDKs will expose flags for an application to handle; in other SDKs flags may be automatically handled by the SDK itself. For more information about the flags unique to your chosen SDK, please refer to the SDK's API reference.
On average, document metadata is about 150 Bytes per item. Couchbase Server keeps all document metadata and keys in RAM and does not remove them from RAM to free up additional space. This means 100 million items with a 70 Byte key and 150 Byte meta data would require approximately 45 GB of RAM at runtime.
As discussed previously in this guide, you can provide an
explicit expiration for a record or let Couchbase assign a
default. The default expiration for any given record is 0, which
signifies indefinite storage. Couchbase will keep the item
stored until you explicitly perform a
delete() on that key. Alternately if
you remove the entire bucket, Couchbase will delete the record.
Expirations are typically set in seconds:
Items < 30 days: if you want to store an item for thirty days or less, you specify the number of seconds until expiration.
Items > 30 days: if you want to store an item for thirty days or more, you specify the an absolute Unix epoch time. Milliseconds will be rounded up to the nearest second. Couchbase Server will delete an item at this time.
If you provide a time to live in seconds that is greater than the number of seconds in 30 days (60 * 60 *24 * 30) Couchbase Server will consider this to be a real Unix epoch time value, rather than interpret it as seconds. It will remove the item at that epoch time.