Skip to content

Commit

Permalink
re-implemented a buffer of the last used filespec
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Apr 6, 2012
1 parent 366d040 commit b795836
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions library/Zend/Cache/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ class Filesystem extends AbstractAdapter
*/
protected $stmtMatch = null;

/**
* An identity for the last filespec
* (cache directory + namespace prefix + key + directory level)
*
* @var string
*/
protected $lastFileSpecId = '';

/**
* The last used filespec
*
* @var string
*/
protected $lastFileSpec = '';

/**
* Set options.
*
Expand Down Expand Up @@ -1600,17 +1615,24 @@ protected function getFileSpec($normalizedKey, array & $normalizedOptions)
$baseOptions = $this->getOptions();
$prefix = $normalizedOptions['namespace'] . $baseOptions->getNamespaceSeparator();

$path = $baseOptions->getCacheDir();
$path = $baseOptions->getCacheDir() . \DIRECTORY_SEPARATOR;
$level = $baseOptions->getDirLevel();
if ( $level > 0 ) {
// create up to 256 directories per directory level
$hash = md5($normalizedKey);
for ($i = 0, $max = ($level * 2); $i < $max; $i+= 2) {
$path .= \DIRECTORY_SEPARATOR . $prefix . $hash[$i] . $hash[$i+1];

$fileSpecId = $path . $prefix . $normalizedKey . '/' . $level;
if ($this->lastFileSpecId !== $fileSpecId) {
if ($level > 0) {
// create up to 256 directories per directory level
$hash = md5($normalizedKey);
for ($i = 0, $max = ($level * 2); $i < $max; $i+= 2) {
$path .= $prefix . $hash[$i] . $hash[$i+1] . \DIRECTORY_SEPARATOR;
}
}

$this->lastFileSpecId = $fileSpecId;
$this->lastFileSpec = $path . $prefix . $normalizedKey;
}

return $path . \DIRECTORY_SEPARATOR . $prefix . $normalizedKey;
return $this->lastFileSpec;
}

/**
Expand Down

0 comments on commit b795836

Please sign in to comment.