These operations are used for storing information into Couchbase
Server and consist of
set. Both operations exist for all SDKs
provided by Couchbase. For some languages, parameters, return
values, and data types may differ. Unique behavior for these store
methods that you should be aware of:
Expiration: By default all documents you store using
will not expire. Removal must be explicit, such as using
delete. If you do set an expiration
to the value 0, this will also indicate no expiration. For
more information, see Section 3.3, “About Document Expiration”
CAS ID/CAS Value: For every value that exists in Couchbase Server, the server will automatically add a unique Check and Set (CAS) value as a 64-bit integer with the item. You can use this value in your implementation to provide basic optimistic concurrency. For more information, see Section 3.7, “Retrieving Items with CAS Values”
For existing keys,
set will overwrite any
existing value if a key already exists; in contrast
add will fail and return an error. If you
replace it will fail if the key does
not already exist.
The following storage limits exist for each type of information that you provide as well as the metadata that Couchbase Server automatically adds to items:
Keys: Can be up to 250 Bytes. Couchbase Server keeps all keys in RAM and does not eject any keys to free up space.
Metadata: This is the information Couchbase Server automatically stores with your value, namely CAS value, expiration and flags. Metadata per document is 60 Bytes for Couchbase 2.0.1 and 54 for Couchbase 2.0.2. This is stored in RAM at all times, and cannot be ejected from RAM.
Values: You can store values up to 1 MB in memcached buckets and up to 20 MB in Couchbase buckets. Values can be any arbitrary binary data or it can be a JSON-encoded document.
Be aware of key and metadata size if you are handling millions of documents or more. Couchbase Server keeps all keys and metadata in RAM and does not remove them to create more space in RAM. One hundred million keys which are 70 Bytes each plus meta data at 54 Bytes each will require about 11.2 GB of RAM for a cluster. This figure does not include caching any values or replica copies of data, if you consider these factors, you would need over 23 GB. For more information, see Couchbase Manual, Sizing Guidelines.