Skip to content

Instantly share code, notes, and snippets.

@TheBlackPlague
Created June 14, 2020 09:44
Show Gist options
  • Save TheBlackPlague/d3b40b2ff8327aec858c1e929af45681 to your computer and use it in GitHub Desktop.
Save TheBlackPlague/d3b40b2ff8327aec858c1e929af45681 to your computer and use it in GitHub Desktop.
<?php
foreach ($configuration->requestList as $request) {
$video = $request->video;
$endpoint = $request->endpoint;
$lowestLatency = $endpoint->dataCenterLatency;
$selectedCache = null;
/**
* @var int $id
* @var Cache $connectedCache
*/
foreach ($endpoint->connectedCaches as $id => $connectedCache) {
$latency = $endpoint->connectedCachesLatency[$id];
if ($latency < $lowestLatency && $connectedCache->canStore($video)) {
$lowestLatency = $latency;
$selectedCache = $connectedCache;
}
}
if ($selectedCache instanceof Cache) {
$selectedCache->store($video);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment