Skip to content

Commit 0ea3233

Browse files
authored
Merge pull request #9 from Devonab/fix/cache-tags-not-supported
fix: support github service without cache tags
2 parents 5ca0cf6 + 4ef8ae8 commit 0ea3233

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
includes:
2+
- vendor/larastan/larastan/extension.neon
23
- phpstan-baseline.neon
34

45
parameters:
@@ -9,4 +10,3 @@ parameters:
910
tmpDir: build/phpstan
1011
checkOctaneCompatibility: true
1112
checkModelProperties: true
12-

src/Services/GitHubService.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,16 @@ public function getLatestTag(?string $repository = null): string
7373
$repository = $repository ?? $this->repository;
7474
$cacheKey = "filament-easy-footer.github.{$repository}.latest-tag";
7575

76-
return Cache::remember(
77-
$cacheKey,
78-
$this->cacheTtl,
79-
fn () => $this->fetchLatestTag($repository) ?? $this->defaultVersion
80-
);
76+
$cachedTag = $this->getCacheWithoutTags($cacheKey);
77+
if ($cachedTag !== null) {
78+
return $cachedTag;
79+
}
80+
81+
$tag = $this->fetchLatestTag($repository) ?? $this->defaultVersion;
82+
83+
$this->setCacheWithoutTags($cacheKey, $tag, $this->cacheTtl);
84+
85+
return $tag;
8186
}
8287

8388
protected function fetchLatestTag(string $repository): ?string
@@ -103,4 +108,24 @@ protected function fetchLatestTag(string $repository): ?string
103108

104109
return null;
105110
}
111+
112+
protected function getCacheWithoutTags(string $key)
113+
{
114+
try {
115+
return Cache::store(config('cache.default'))->get($key);
116+
} catch (\Exception $e) {
117+
report($e);
118+
119+
return null;
120+
}
121+
}
122+
123+
protected function setCacheWithoutTags(string $key, $value, int $ttl): void
124+
{
125+
try {
126+
Cache::store(config('cache.default'))->put($key, $value, $ttl);
127+
} catch (\Exception $e) {
128+
report($e);
129+
}
130+
}
106131
}

0 commit comments

Comments
 (0)