Skip to content

Commit

Permalink
remove static cache
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Aug 8, 2024
1 parent 56d4305 commit 352b5c2
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/SelfUpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
class SelfUpdateManager
{
protected array $options;
private ?array $latestRelease = null;

public function __construct(protected string $gitHubRepository, protected string $currentVersion, protected string $applicationName, array $options){
// Options need to be passed in the constructor since we cache the latestRelease which may vary based on options.
$this->options = array_merge([
'preview' => false,
'compatible' => false,
Expand All @@ -50,10 +48,6 @@ public function isUpToDate(): bool {
*/
public function getLatestReleaseFromGithub(): ?array
{
if (null !== $this->latestRelease) {
return $this->latestRelease;
}

foreach ($this->getReleasesFromGithub() as $releaseVersion => $release) {
// We do not care about this release if it does not contain assets.
if (!isset($release['assets'][0]) || !is_object($release['assets'][0])) {
Expand All @@ -75,12 +69,11 @@ public function getLatestReleaseFromGithub(): ?array
continue;
}

$this->latestRelease = [
return [
'version' => $releaseVersion,
'tag_name' => $release['tag_name'],
'download_url' => $release['assets'][0]->browser_download_url,
];
return $this->latestRelease;
}

return null;
Expand All @@ -89,6 +82,8 @@ public function getLatestReleaseFromGithub(): ?array
/**
* Get all releases from GitHub.
*
* Network requests are cached up to the max-age in the GitHub response (i.e., 60 seconds).
*
* @return array
*
* @throws \Exception
Expand Down

0 comments on commit 352b5c2

Please sign in to comment.