From 685ade6f02f607200e0b92d6f09abc4a5814e386 Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 5 Nov 2008 14:59:26 +0000 Subject: Added "add" method to cache only if it doesn't exist already. git-svn-id: https://code.elgg.org/elgg/trunk@2404 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/cache.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'engine') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index fa5f990df..e8b996e59 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -127,6 +127,23 @@ */ abstract public function clear(); + /** + * Add a key only if it doesn't already exist. + * Implemented simply here, if you extend this class and your caching engine provides a better way then + * override this accordingly. + * + * @param string $key + * @param string $data + * @return bool + */ + public function add($key, $data) + { + if (!isset($this[$key])) + return $this->save($key, $data); + + return false; + } + // ARRAY ACCESS INTERFACE ////////////////////////////////////////////////////////// function offsetSet($key, $value) { @@ -388,7 +405,7 @@ /** - * A simple function that selects the default caching engine. + * A simple function that selects the default memory caching engine. * * This function provides a central way to get a cache for storing local variables. * -- cgit v1.2.3