Skip to content

Commit

Permalink
File length caching by filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Apr 16, 2022
1 parent 2ca1e5c commit dd0f152
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
14 changes: 14 additions & 0 deletions SSL/SSLTrackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SSLTrackCache extends SSLTrackFactory
*/
protected $factory;
protected $tracks = array();
protected $file_lengths = array();

public function __construct()
{
Expand All @@ -55,4 +56,17 @@ public function newTrack()
{
return $this->factory->newRuntimeCachingTrack($this);
}

public function setLengthByFullpath($fullpath, $length)
{
$this->file_lengths[$fullpath] = $length;
}

public function getLengthByFullpath($fullpath)
{
if(isset($this->file_lengths[$fullpath]))
{
return $this->file_lengths[$fullpath];
}
}
}
25 changes: 19 additions & 6 deletions SSL/Structs/RuntimeCachingSSLTrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,26 @@ public function setLengthIfUnknown()

if($cached_track)
{
$cached_length = $cached_track->getLength();
if(isset($cached_length))
{
$this->setLength($cached_length);
}
$length = $cached_track->getLength();
}


if(!isset($length))
{
// either there's no cached track or it was cached without a length.
// it may also be cached by file path.
$length = $this->track_cache->getLengthByFullpath($this->getFullpath());
}

if(isset($length))
{
$this->setLength($length);
return;
}

// if we got here, we did not get the length from cache.
parent::setLengthIfUnknown();

// we still may not have it, but we checked the file this time.
$length = $this->getLength();

// save in the cache, for next time.
Expand All @@ -92,6 +103,8 @@ public function setLengthIfUnknown()
{
$this->track_cache->register($this);
}

$this->track_cache->setLengthByFullpath($this->getFullpath(), $length);
}
}
}
Expand Down

0 comments on commit dd0f152

Please sign in to comment.