Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up old code in cache.php file #12183

Merged
merged 3 commits into from
Jan 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 23 additions & 88 deletions libraries/joomla/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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']);
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -390,18 +335,18 @@ 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
* NOTE drivers with lock need also unlock or unlocking will fail because of false $id
*/
$handler = $this->_getStorage();

if (!($handler instanceof Exception) && $this->_options['locking'] == true)
if ($this->_options['locking'] == true)
{
$locked = $handler->lock($id, $group, $locktime);

Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down