Skip to content
Open
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
25 changes: 23 additions & 2 deletions Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class FileCache extends AbstractCache
/** @var string $separator */
private $_separator = '--s--';

/** @var string last id fetched */
private $_lastId = null;

/** @var string last data fetched */
private $_lastData = null;


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -104,7 +111,14 @@ public function getIds()
*/
protected function _doFetch($id)
{
return unserialize(file_get_contents($this->getFileName($id)));
//LifetimeFileCache will perform a fetch during contains(), so by
//retaining that data we can greatly speedup the subsequent fetch()
if ($id != $this->_lastId) {
$this->_lastId=$id;
$this->_lastData=unserialize(file_get_contents($this->getFileName($id)));
}

return $this->_lastData;
}

/**
Expand All @@ -120,19 +134,26 @@ protected function _doContains($id)
*/
protected function _doSave($id, $data, $lifeTime = 0)
{
$this->_lastId=$id;
$this->_lastData=$data;
return (bool) file_put_contents($this->getFileName($id), serialize($data));
}

/**
* {@inheritdoc}
*/
protected function _doDelete($id)
{
{
$file = $this->getFileName($id);

if (file_exists($file)) {
return unlink($file);
}
if ($id == $this->_lastId) {
$this->_lastId=null;
$this->_lastData=null;
}


return true;
}
Expand Down