Skip to content
Permalink
Browse files

Fixed filecache

  • Loading branch information...
JuhaniGeniem committed Jun 4, 2019
1 parent b92bc17 commit b2e7a71efa875befdc10b3ffd22ce4c710231d22
Showing with 11 additions and 17 deletions.
  1. +11 −17 dust/Dust.php
@@ -142,18 +142,12 @@ public function compileFn($source, $name = NULL) {
* @return null|string
*/
public function resolveAbsoluteDustFilePath($path, $basePath = NULL) {
//add extension if necessary
if(substr_compare($path, self::FILE_EXTENSION, -5, 5) !== 0)
{
$path .= self::FILE_EXTENSION;
}
// Get from cache if the file is already found.
if ( isset( static::$dustFileCache[ $path ] ) ) {
return static::$dustFileCache[ $path ];
}
//try the current path
$possible = realpath($path);
@@ -162,21 +156,21 @@ public function resolveAbsoluteDustFilePath($path, $basePath = NULL) {
return $possible;
}
//now try each of the included directories
foreach ( $this->includedDirectories as $directory ) {
foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory, \RecursiveDirectoryIterator::SKIP_DOTS ) ) as $file ) {
if ( substr_compare($file, "/".$path, strlen($file)-strlen("/".$path), strlen("/".$path)) === 0 ) {
// Cache the found file.
static::$dustFileCache[ $path ] = (string) $file;
return (string)$file;
// Populate cache when run the first time.
if (empty(static::$dustFileCache)) {
foreach ($this->includedDirectories as $directory) {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS)) as $file) {
static::$dustFileCache[] = $file;
}
}
}
// Cache the not found result to prevent subsequent searches.
static::$dustFileCache[ $path ] = NULL;
// Loop through the cache.
foreach (static::$dustFileCache as $file) {
if (substr_compare($file, "/" . $path, strlen($file) - strlen("/" . $path), strlen("/" . $path)) === 0) {
return (string)$file;
}
}
return NULL;
}

0 comments on commit b2e7a71

Please sign in to comment.
You can’t perform that action at this time.