6
6
7
7
use AUS \SsiInclude \Utility \FilenameUtility ;
8
8
use InvalidArgumentException ;
9
- use TYPO3 \CMS \Core \Cache \Backend \AbstractBackend ;
10
- use TYPO3 \CMS \Core \Cache \Backend \BackendInterface ;
11
- use TYPO3 \CMS \Core \Cache \Backend \TaggableBackendInterface ;
12
- use TYPO3 \CMS \Core \Cache \CacheManager ;
9
+ use TYPO3 \CMS \Core \Cache \Backend \Typo3DatabaseBackend ;
13
10
use TYPO3 \CMS \Core \Cache \Exception \NoSuchCacheException ;
14
- use TYPO3 \CMS \Core \Cache \Frontend \FrontendInterface ;
15
11
use TYPO3 \CMS \Core \Core \Environment ;
16
12
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
17
13
use Webimpress \SafeWriter \Exception \ExceptionInterface ;
18
14
use Webimpress \SafeWriter \FileWriter ;
19
15
20
- class SsiIncludeCacheBackend extends AbstractBackend implements TaggableBackendInterface
16
+ class SsiIncludeCacheBackend extends Typo3DatabaseBackend
21
17
{
22
- private readonly TaggableBackendInterface $ concrete ;
23
-
24
- private string $ concreteCache = 'aus_ssi_include_concrete_cache ' ;
25
-
26
18
private readonly FilenameUtility $ filenameUtility ;
27
19
28
20
/**
@@ -35,30 +27,26 @@ class SsiIncludeCacheBackend extends AbstractBackend implements TaggableBackendI
35
27
/**
36
28
* @inheritdoc
37
29
* @param array<string, mixed> $options
38
- * @throws NoSuchCacheException
39
30
*/
40
31
public function __construct ($ context , array $ options = [])
41
32
{
42
33
parent ::__construct ($ context , $ options );
43
34
44
35
$ this ->filenameUtility = GeneralUtility::makeInstance (FilenameUtility::class);
36
+ }
45
37
46
- $ cacheManager = GeneralUtility::makeInstance (CacheManager::class);
47
- assert ($ cacheManager instanceof CacheManager);
48
- $ concrete = $ cacheManager ->getCache ($ this ->concreteCache )->getBackend ();
49
- assert ($ concrete instanceof BackendInterface);
50
- assert ($ concrete instanceof TaggableBackendInterface);
51
- $ this ->concrete = $ concrete ;
38
+ public function getSsiIncludeDir (): string
39
+ {
40
+ return $ this ->ssiIncludeDir ;
52
41
}
53
42
54
43
/**
55
- * The cache identifier of the concrete cache which is used to save
56
- * the data. If storeData is false, it also creates an empty cache entry
57
- * to include with caching framework and have the identifier tied to the cache tags and lifetime
44
+ * @return list<string>
58
45
*/
59
- public function setConcreteCache ( string $ concreteCache ): void
46
+ private function getSsiIncludeDirFiles ( ): array
60
47
{
61
- $ this ->concreteCache = $ concreteCache ;
48
+ $ publicIncludeDir = Environment::getPublicPath () . $ this ->ssiIncludeDir ;
49
+ return glob ($ publicIncludeDir . '*.html ' ) ?: [];
62
50
}
63
51
64
52
/**
@@ -78,19 +66,6 @@ public function setStoreData(bool $storeData): void
78
66
$ this ->storeData = $ storeData ;
79
67
}
80
68
81
- public function getSsiIncludeDir (): string
82
- {
83
- return $ this ->ssiIncludeDir ;
84
- }
85
-
86
- /**
87
- * @inheritdoc
88
- */
89
- public function setCache (FrontendInterface $ cache ): void
90
- {
91
- $ this ->cache = $ cache ;
92
- }
93
-
94
69
/**
95
70
* @inheritdoc
96
71
* @param array<string> $tags
@@ -102,23 +77,15 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
102
77
throw new InvalidArgumentException ('Data must be a string ' , 1616420133 );
103
78
}
104
79
80
+ parent ::set ($ entryIdentifier , $ this ->storeData ? $ data : '' , $ tags , $ lifetime );
81
+
105
82
$ absolutePath = $ this ->filenameUtility ->getAbsoluteFilename ($ entryIdentifier );
106
83
107
84
GeneralUtility::mkdir_deep (dirname ($ absolutePath ));
108
85
GeneralUtility::fixPermissions (dirname ($ absolutePath ));
109
86
110
87
FileWriter::writeFile ($ absolutePath , $ data );
111
88
GeneralUtility::fixPermissions ($ absolutePath );
112
-
113
- $ this ->concrete ->set ($ entryIdentifier , $ this ->storeData ? $ data : '' , $ tags , $ lifetime );
114
- }
115
-
116
- /**
117
- * @inheritdoc
118
- */
119
- public function get ($ entryIdentifier ): false |string
120
- {
121
- return $ this ->concrete ->get ($ entryIdentifier );
122
89
}
123
90
124
91
/**
@@ -127,7 +94,7 @@ public function get($entryIdentifier): false|string
127
94
*/
128
95
public function has ($ entryIdentifier ): bool
129
96
{
130
- $ data = $ this -> concrete -> has ($ entryIdentifier );
97
+ $ data = parent :: has ($ entryIdentifier );
131
98
if (!$ data ) {
132
99
return false ;
133
100
}
@@ -147,7 +114,7 @@ public function remove($entryIdentifier): bool
147
114
unlink ($ absoluteFile );
148
115
}
149
116
150
- return $ this -> concrete -> remove ($ entryIdentifier );
117
+ return parent :: remove ($ entryIdentifier );
151
118
}
152
119
153
120
/**
@@ -159,7 +126,7 @@ public function flush(): void
159
126
unlink ($ file );
160
127
}
161
128
162
- $ this -> concrete -> flush ();
129
+ parent :: flush ();
163
130
}
164
131
165
132
/**
@@ -169,7 +136,7 @@ public function flush(): void
169
136
public function collectGarbage (): void
170
137
{
171
138
// remove outdated things
172
- $ this -> concrete -> collectGarbage ();
139
+ parent :: collectGarbage ();
173
140
174
141
// get all files, and the file that has no entry remove them
175
142
$ files = $ this ->getSsiIncludeDirFiles ();
@@ -200,7 +167,7 @@ public function flushByTag($tag): void
200
167
*/
201
168
public function flushByTags (array $ tags ): void
202
169
{
203
- $ this -> concrete -> flushByTags ($ tags );
170
+ parent :: flushByTags ($ tags );
204
171
foreach ($ tags as $ tag ) {
205
172
$ this ->flushByTag ($ tag );
206
173
}
@@ -213,15 +180,6 @@ public function flushByTags(array $tags): void
213
180
*/
214
181
public function findIdentifiersByTag ($ tag ): array
215
182
{
216
- return $ this ->concrete ->findIdentifiersByTag ($ tag );
217
- }
218
-
219
- /**
220
- * @return list<string>
221
- */
222
- private function getSsiIncludeDirFiles (): array
223
- {
224
- $ publicIncludeDir = Environment::getPublicPath () . $ this ->ssiIncludeDir ;
225
- return glob ($ publicIncludeDir . '*.html ' ) ?: [];
183
+ return parent ::findIdentifiersByTag ($ tag );
226
184
}
227
185
}
0 commit comments