|
|
@@ -165,6 +165,15 @@ abstract class CacheEngine
|
|
|
*/
|
|
|
abstract public function delete($key);
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Delete all keys from the cache
|
|
|
+ *
|
|
|
+ * @param bool $check if true will check expiration, otherwise delete all
|
|
|
+ * @return bool True if the cache was successfully cleared, false otherwise
|
|
|
+ */
|
|
|
+ abstract public function clear($check);
|
|
|
+
|
|
|
/**
|
|
|
* Deletes keys from the cache
|
|
|
*
|
|
|
@@ -182,12 +191,23 @@ abstract class CacheEngine
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Delete all keys from the cache
|
|
|
+ * Add a key to the cache if it does not already exist.
|
|
|
*
|
|
|
- * @param bool $check if true will check expiration, otherwise delete all
|
|
|
- * @return bool True if the cache was successfully cleared, false otherwise
|
|
|
+ * Defaults to a non-atomic implementation. Subclasses should
|
|
|
+ * prefer atomic implementations.
|
|
|
+ *
|
|
|
+ * @param string $key Identifier for the data.
|
|
|
+ * @param mixed $value Data to be cached.
|
|
|
+ * @return bool True if the data was successfully cached, false on failure.
|
|
|
*/
|
|
|
- abstract public function clear($check);
|
|
|
+ public function add($key, $value)
|
|
|
+ {
|
|
|
+ $cachedValue = $this->read($key);
|
|
|
+ if ($cachedValue === false) {
|
|
|
+ return $this->write($key, $value);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Clears all values belonging to a group. Is up to the implementing engine
|