3 namespace Drupal\Core\KeyValueStore;
6 * Defines the interface for key/value store implementations.
8 interface KeyValueStoreInterface {
11 * Returns the name of this collection.
14 * The name of this collection.
16 public function getCollectionName();
19 * Returns whether a given key exists in the store.
25 * TRUE if the key exists, FALSE otherwise.
27 public function has($key);
30 * Returns the stored value for a given key.
33 * The key of the data to retrieve.
34 * @param mixed $default
35 * The default value to use if the key is not found.
38 * The stored value, or the default value if no value exists.
40 public function get($key, $default = NULL);
43 * Returns the stored key/value pairs for a given set of keys.
46 * A list of keys to retrieve.
49 * An associative array of items successfully returned, indexed by key.
51 * @todo What's returned for non-existing keys?
53 public function getMultiple(array $keys);
56 * Returns all stored key/value pairs in the collection.
59 * An associative array containing all stored items in the collection.
61 public function getAll();
64 * Saves a value for a given key.
67 * The key of the data to store.
71 public function set($key, $value);
74 * Saves a value for a given key if it does not exist yet.
77 * The key of the data to store.
82 * TRUE if the data was set, FALSE if it already existed.
84 public function setIfNotExists($key, $value);
87 * Saves key/value pairs.
90 * An associative array of key/value pairs.
92 public function setMultiple(array $data);
99 * @param string $new_key
102 public function rename($key, $new_key);
105 * Deletes an item from the key/value store.
108 * The item name to delete.
110 public function delete($key);
113 * Deletes multiple items from the key/value store.
116 * A list of item names to delete.
118 public function deleteMultiple(array $keys);
121 * Deletes all items from the key/value store.
123 public function deleteAll();