|
|
@@ -203,6 +203,44 @@ class Cache {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Write data for many keys into cache.
|
|
|
+ *
|
|
|
+ * ### Usage:
|
|
|
+ *
|
|
|
+ * Writing to the active cache config:
|
|
|
+ *
|
|
|
+ * `Cache::writeMany(array('cached_data_1' => 'data 1', 'cached_data_2' => 'data 2'));`
|
|
|
+ *
|
|
|
+ * Writing to a specific cache config:
|
|
|
+ *
|
|
|
+ * `Cache::writeMany(array('cached_data_1' => 'data 1', 'cached_data_2' => 'data 2'), 'long_term');`
|
|
|
+ *
|
|
|
+ * @param array $data An array of data to be stored in the cache
|
|
|
+ * @param string $config Optional string configuration name to write to. Defaults to 'default'
|
|
|
+ * @return array of bools for each key provided, indicating true for success or false for fail
|
|
|
+ * @throws \Cake\Error\Exception
|
|
|
+ */
|
|
|
+ public static function writeMany($data, $config = 'default') {
|
|
|
+ $engine = static::engine($config);
|
|
|
+ if (!$engine) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $return = $engine->writeMany($data);
|
|
|
+ foreach ($return as $key => $success) {
|
|
|
+ if ($success === false && !empty($data[$key])) {
|
|
|
+ throw new Error\Exception(sprintf(
|
|
|
+ '%s cache was unable to write \'%s\' to %s cache',
|
|
|
+ $config,
|
|
|
+ $key,
|
|
|
+ get_class($engine)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* Read a key from the cache.
|
|
|
*
|
|
|
* ### Usage:
|
|
|
@@ -229,6 +267,32 @@ class Cache {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Read multiple keys from the cache.
|
|
|
+ *
|
|
|
+ * ### Usage:
|
|
|
+ *
|
|
|
+ * Reading multiple keys from the active cache configuration.
|
|
|
+ *
|
|
|
+ * `Cache::readMany(array('my_data_1', 'my_data_2)));`
|
|
|
+ *
|
|
|
+ * Reading from a specific cache configuration.
|
|
|
+ *
|
|
|
+ * `Cache::readMany(array('my_data_1', 'my_data_2), 'long_term');`
|
|
|
+ *
|
|
|
+ * @param array $keys an array of keys to fetch from the cache
|
|
|
+ * @param string $config optional name of the configuration to use. Defaults to 'default'
|
|
|
+ * @return array An array containing, for each of the given $keys, the cached data or false if cached data could not be
|
|
|
+ * retreived
|
|
|
+ */
|
|
|
+ public static function readMany($keys, $config = 'default') {
|
|
|
+ $engine = static::engine($config);
|
|
|
+ if (!$engine) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $engine->readMany($keys);
|
|
|
+ }
|
|
|
+/**
|
|
|
* Increment a number under the key and return incremented value.
|
|
|
*
|
|
|
* @param string $key Identifier for the data
|
|
|
@@ -291,6 +355,33 @@ class Cache {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Delete many keys from the cache.
|
|
|
+ *
|
|
|
+ * ### Usage:
|
|
|
+ *
|
|
|
+ * Deleting multiple keys from the active cache configuration.
|
|
|
+ *
|
|
|
+ * `Cache::deleteMany(array('my_data_1', 'my_data_2'));`
|
|
|
+ *
|
|
|
+ * Deleting from a specific cache configuration.
|
|
|
+ *
|
|
|
+ * `Cache::deleteMany(array('my_data_1', 'my_data_2), 'long_term');`
|
|
|
+ *
|
|
|
+ * @param array $keys Array of cache keys to be deleted
|
|
|
+ * @param string $config name of the configuration to use. Defaults to 'default'
|
|
|
+ * @return array of boolean values that are true if the value was successfully deleted, false if it didn't exist or
|
|
|
+ * couldn't be removed
|
|
|
+ */
|
|
|
+ public static function deleteMany($keys, $config = 'default') {
|
|
|
+ $engine = static::engine($config);
|
|
|
+ if (!$engine) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $engine->deleteMany($keys);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* Delete all keys from the cache.
|
|
|
*
|
|
|
* @param boolean $check if true will check expiration, otherwise delete all
|