From d016a6c2aede57915c8517b5fce2aca98ec172da Mon Sep 17 00:00:00 2001 From: Tomasz Narloch Date: Thu, 12 Jan 2017 19:30:55 +0100 Subject: [PATCH] Clean up old code in cache.php file (#12183) * Clean up in cache - part 1 * Remove old php4 style to catch exception which currently is useless. * Add shorten version of ternary pperators. * Add fix for contains() --- libraries/joomla/cache/cache.php | 111 +++++++------------------------ 1 file changed, 23 insertions(+), 88 deletions(-) diff --git a/libraries/joomla/cache/cache.php b/libraries/joomla/cache/cache.php index a4eebd659ef31..0ee6be6ac800f 100644 --- a/libraries/joomla/cache/cache.php +++ b/libraries/joomla/cache/cache.php @@ -192,15 +192,7 @@ public function contains($id, $group = null) // Get the default group $group = $group ?: $this->_options['defaultgroup']; - // Get the storage - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->contains($id, $group); - } - - return false; + return $this->_getStorage()->contains($id, $group); } /** @@ -221,17 +213,9 @@ public function get($id, $group = null) } // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; - - // Get the storage - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->get($id, $group, $this->_options['checkTime']); - } + $group = $group ?: $this->_options['defaultgroup']; - return false; + return $this->_getStorage()->get($id, $group, $this->_options['checkTime']); } /** @@ -248,15 +232,7 @@ public function getAll() return false; } - // Get the storage - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->getAll(); - } - - return false; + return $this->_getStorage()->getAll(); } /** @@ -278,17 +254,10 @@ public function store($data, $id, $group = null) } // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; + $group = $group ?: $this->_options['defaultgroup']; // Get the storage and store the cached data - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->store($id, $group, $data); - } - - return false; + return $this->_getStorage()->store($id, $group, $data); } /** @@ -304,17 +273,9 @@ public function store($data, $id, $group = null) public function remove($id, $group = null) { // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; - - // Get the storage - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->remove($id, $group); - } + $group = $group ?: $this->_options['defaultgroup']; - return false; + return $this->_getStorage()->remove($id, $group); } /** @@ -333,17 +294,9 @@ public function remove($id, $group = null) public function clean($group = null, $mode = 'group') { // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; - - // Get the storage handler - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->clean($group, $mode); - } + $group = $group ?: $this->_options['defaultgroup']; - return false; + return $this->_getStorage()->clean($group, $mode); } /** @@ -355,15 +308,7 @@ public function clean($group = null, $mode = 'group') */ public function gc() { - // Get the storage handler - $handler = $this->_getStorage(); - - if (!($handler instanceof Exception)) - { - return $handler->gc(); - } - - return false; + return $this->_getStorage()->gc(); } /** @@ -390,10 +335,10 @@ public function lock($id, $group = null, $locktime = null) } // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; + $group = $group ?: $this->_options['defaultgroup']; // Get the default locktime - $locktime = ($locktime) ? $locktime : $this->_options['locktime']; + $locktime = $locktime ?: $this->_options['locktime']; /* * Allow storage handlers to perform locking on their own @@ -401,7 +346,7 @@ public function lock($id, $group = null, $locktime = null) */ $handler = $this->_getStorage(); - if (!($handler instanceof Exception) && $this->_options['locking'] == true) + if ($this->_options['locking'] == true) { $locked = $handler->lock($id, $group, $locktime); @@ -422,7 +367,7 @@ public function lock($id, $group = null, $locktime = null) if ($this->_options['locking'] == true) { - $data_lock = $this->get($id2, $group); + $data_lock = $handler->get($id2, $group, $this->_options['checkTime']); } else { @@ -445,14 +390,14 @@ public function lock($id, $group = null, $locktime = null) } usleep(100); - $data_lock = $this->get($id2, $group); + $data_lock = $handler->get($id2, $group, $this->_options['checkTime']); $lock_counter++; } } if ($this->_options['locking'] == true) { - $returning->locked = $this->store(1, $id2, $group); + $returning->locked = $handler->store(1, $id2, $group); } // Revert lifetime to previous one @@ -478,31 +423,21 @@ public function unlock($id, $group = null) return false; } - $unlock = false; - // Get the default group - $group = ($group) ? $group : $this->_options['defaultgroup']; + $group = $group ?: $this->_options['defaultgroup']; // Allow handlers to perform unlocking on their own $handler = $this->_getStorage(); - if (!($handler instanceof Exception)) - { - $unlocked = $handler->unlock($id, $group); - - if ($unlocked !== false) - { - return $unlocked; - } - } + $unlocked = $handler->unlock($id, $group); - // Fallback - if ($this->getCaching()) + if ($unlocked !== false) { - $unlock = $this->remove($id . '_lock', $group); + return $unlocked; } - return $unlock; + // Fallback + return $handler->remove($id . '_lock', $group); } /**