2121use TYPO3 \CMS \Core \Cache \Backend \Typo3DatabaseBackend ;
2222use TYPO3 \CMS \Core \Cache \Exception ;
2323use TYPO3 \CMS \Core \Cache \Exception \InvalidDataException ;
24+ use TYPO3 \CMS \Core \Cache \Frontend \FrontendInterface ;
2425use TYPO3 \CMS \Core \Core \Environment ;
2526use TYPO3 \CMS \Core \Http \RequestFactory ;
2627use TYPO3 \CMS \Core \Utility \GeneralUtility ;
2728
28- class NginxCacheBackend extends Typo3DatabaseBackend implements TransientBackendInterface
29+ final readonly class NginxCacheBackend implements TransientBackendInterface
2930{
30- /**
31- * Saves data in a cache file.
32- *
33- * @param string $entryIdentifier An identifier for this specific cache entry
34- * @param string $data The data to be stored
35- * @param array $tags Tags to associate with this cache entry
36- * @param int $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
37- * @return void
38- * @throws Exception if no cache frontend has been set.
39- * @throws InvalidDataException if the data to be stored is not a string.
40- */
41- public function set ($ entryIdentifier , $ data , array $ tags = array (), $ lifetime = null )
42- {
43- parent ::set ($ entryIdentifier , $ data , $ tags , $ lifetime );
31+ private Typo3DatabaseBackend $ backend ;
4432
45- if ( $ lifetime === 0 ) {
46- // unlimited is not supported by nginx
47- $ lifetime = 24 * 60 * 60 ;
48- }
33+ public function __construct ()
34+ {
35+ $ this -> backend = new Typo3DatabaseBackend () ;
36+ }
4937
50- /* Note: We use an explicit opt-in strategy to define requests as cachable.
51- * That means this functionality relies on the "fastcgi_cache_valid 0"
52- * in nginx.conf as documented in README.rst */
53- header ('X-Accel-Expires: ' . $ lifetime );
38+ public function set (string $ entryIdentifier , mixed $ data , array $ tags = [], ?int $ lifetime = null ): void
39+ {
40+ $ this ->backend ->set ($ entryIdentifier , $ data , $ tags , $ lifetime );
5441 }
5542
56- /**
57- * Removes all cache entries matching the specified identifier.
58- *
59- * @param string $entryIdentifier Specifies the cache entry to remove
60- * @return bool TRUE if (at least) an entry could be removed or FALSE if no entry was found
61- */
62- public function remove ($ entryIdentifier )
43+ public function remove (string $ entryIdentifier ): bool
6344 {
64- $ url = parent :: get ($ entryIdentifier );
45+ $ url = $ this -> backend -> get ($ entryIdentifier );
6546 if ($ url === false ) {
6647 /* The key is not available. Do nothing. */
6748 return false ;
6849 }
6950
7051 $ this ->purge ($ url );
7152
72- return parent :: remove ($ entryIdentifier );
53+ return $ this -> backend -> remove ($ entryIdentifier );
7354 }
7455
75- /**
76- * Removes all cache entries of this cache.
77- *
78- * @return void
79- */
80- public function flush ()
56+ public function flush (): void
8157 {
8258 /* FIXME: this won't work for cli requests. We could try do derive the site_url from
8359 * existing cache entries (using findIdentifierByTag?).
@@ -89,16 +65,10 @@ public function flush()
8965 $ url = GeneralUtility::getIndpEnv ('TYPO3_SITE_URL ' ) . '* ' ;
9066 $ this ->purge ($ url );
9167
92- parent :: flush ();
68+ $ this -> backend -> flush ();
9369 }
9470
95- /**
96- * Removes all cache entries of this cache which are tagged by the specified tag.
97- *
98- * @param string $tag The tag the entries must have
99- * @return void
100- */
101- public function flushByTag ($ tag )
71+ public function flushByTag (string $ tag ): void
10272 {
10373 $ identifiers = $ this ->findIdentifiersByTag ($ tag );
10474 foreach ($ identifiers as $ identifier ) {
@@ -107,12 +77,9 @@ public function flushByTag($tag)
10777 }
10878
10979 /**
110- * Removes all cache entries of this cache which are tagged by any of the specified tags.
111- *
112- * @param string[] $tags List of tags
113- * @return void
80+ * @param list<string> $tasgs
11481 */
115- public function flushByTags (array $ tags )
82+ public function flushByTags (array $ tags ): void
11683 {
11784 array_walk ($ tags , [$ this , 'flushByTag ' ]);
11885 }
@@ -150,4 +117,29 @@ protected function purge(string $url): string
150117
151118 return $ content ;
152119 }
120+
121+ public function get (string $ entryIdentifier ): mixed
122+ {
123+ return $ this ->backend ->get ($ entryIdentifier );
124+ }
125+
126+ public function has (string $ entryIdentifier ): bool
127+ {
128+ return $ this ->backend ->has ($ entryIdentifier );
129+ }
130+
131+ public function collectGarbage (): void
132+ {
133+ $ this ->backend ->collectGarbage ();
134+ }
135+
136+ public function setCache (FrontendInterface $ cache ): void
137+ {
138+ $ this ->backend ->setCache ($ cache );
139+ }
140+
141+ public function getTableDefinitions (): string
142+ {
143+ return $ this ->backend ->getTableDefinitions ();
144+ }
153145}
0 commit comments