Skip to content

Commit d14402f

Browse files
committed
#25 fix: RSS endpoint again
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent aa0df47 commit d14402f

2 files changed

Lines changed: 8 additions & 17 deletions

File tree

src/Controller/AppReleaseRSSFeedController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace App\Controller;
44

55
use App\Entity\AppRelease;
6-
use App\Service\ReleaseApi;
76
use Doctrine\Persistence\ManagerRegistry;
87
use Michelf\Markdown;
8+
use Psr\Cache\CacheItemPoolInterface;
99
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1010
use Symfony\Component\HttpFoundation\Response;
1111
use Symfony\Component\Routing\Attribute\Route;
@@ -20,11 +20,11 @@ class AppReleaseRSSFeedController extends AbstractController
2020
* http://api.qownnotes.org/rss/app-releases
2121
*/
2222
#[Route('/rss/app-releases')]
23-
public function appReleases(ManagerRegistry $doctrine): Response
23+
public function appReleases(ManagerRegistry $doctrine, CacheItemPoolInterface $cache): Response
2424
{
25-
$cacheDriver = ReleaseApi::getCacheDriver();
25+
$cacheItem = $cache->getItem(self::CACHE_KEY);
2626

27-
if (!$cacheDriver->contains(self::CACHE_KEY)) {
27+
if (!$cacheItem->isHit()) {
2828
$projectUrl = 'https://www.qownnotes.org';
2929

3030
$xml = new \DOMDocument('1.0', 'UTF-8'); // Create new DOM document.
@@ -117,9 +117,11 @@ public function appReleases(ManagerRegistry $doctrine): Response
117117

118118
$xmlString = $xml->saveXML();
119119

120-
$cacheDriver->save(self::CACHE_KEY, $xmlString, 60);
120+
$cacheItem->set($xmlString);
121+
$cacheItem->expiresAfter(60);
122+
$cache->save($cacheItem);
121123
} else {
122-
$xmlString = $cacheDriver->fetch(self::CACHE_KEY);
124+
$xmlString = $cacheItem->get();
123125
}
124126

125127
return new Response($xmlString, 200, ['Content-Type' => 'text/xml']);

src/Service/ReleaseApi.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use App\Entity\AppRelease;
1111
use App\Entity\LatestRelease;
12-
use Doctrine\Common\Cache\PhpFileCache;
1312
use Doctrine\Common\Collections\ArrayCollection;
1413
use Doctrine\ORM\EntityManagerInterface;
1514
use GuzzleHttp\Client;
@@ -500,14 +499,4 @@ public function getEnv(string $varName, $default = '')
500499

501500
return false === $value ? ($_ENV[$varName] ?? $default) : $value;
502501
}
503-
504-
/**
505-
* @return PhpFileCache
506-
*/
507-
public static function getCacheDriver()
508-
{
509-
return new PhpFileCache(
510-
'/tmp'
511-
);
512-
}
513502
}

0 commit comments

Comments
 (0)