@@ -35,12 +35,13 @@ trait PhpFilesTrait
35
35
private $ files = [];
36
36
37
37
private static $ startTime ;
38
+ private static $ valuesCache = [];
38
39
39
40
public static function isSupported ()
40
41
{
41
42
self ::$ startTime = self ::$ startTime ?? $ _SERVER ['REQUEST_TIME ' ] ?? time ();
42
43
43
- return \function_exists ('opcache_invalidate ' ) && ( ' cli ' !== \ PHP_SAPI || filter_var (ini_get ('opcache.enable_cli ' ), FILTER_VALIDATE_BOOLEAN )) && filter_var (ini_get ('opcache.enable ' ), FILTER_VALIDATE_BOOLEAN );
44
+ return \function_exists ('opcache_invalidate ' ) && filter_var (ini_get ('opcache.enable ' ), FILTER_VALIDATE_BOOLEAN ) && (! \in_array (\ PHP_SAPI , [ ' cli ' , ' phpdbg ' ], true ) || filter_var (ini_get ('opcache.enable_cli ' ), FILTER_VALIDATE_BOOLEAN ) );
44
45
}
45
46
46
47
/**
@@ -54,7 +55,7 @@ public function prune()
54
55
55
56
set_error_handler ($ this ->includeHandler );
56
57
try {
57
- foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this ->directory , \FilesystemIterator::SKIP_DOTS ), \RecursiveIteratorIterator::LEAVES_ONLY ) as $ file ) {
58
+ foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this ->directory , \FilesystemIterator::SKIP_DOTS | \FilesystemIterator:: CURRENT_AS_PATHNAME ), \RecursiveIteratorIterator::LEAVES_ONLY ) as $ file ) {
58
59
try {
59
60
if (\is_array ($ expiresAt = include $ file )) {
60
61
$ expiresAt = $ expiresAt [0 ];
@@ -100,7 +101,6 @@ protected function doFetch(array $ids)
100
101
} elseif (!\is_object ($ value )) {
101
102
$ values [$ id ] = $ value ;
102
103
} elseif (!$ value instanceof LazyValue) {
103
- // calling a Closure is for @deprecated BC and should be removed in Symfony 5.0
104
104
$ values [$ id ] = $ value ();
105
105
} elseif (false === $ values [$ id ] = include $ value ->file ) {
106
106
unset($ values [$ id ], $ this ->values [$ id ]);
@@ -123,14 +123,20 @@ protected function doFetch(array $ids)
123
123
try {
124
124
$ file = $ this ->files [$ id ] ?? $ this ->files [$ id ] = $ this ->getFile ($ id );
125
125
126
- if (\is_array ($ expiresAt = include $ file )) {
126
+ if (isset (self ::$ valuesCache [$ file ])) {
127
+ [$ expiresAt , $ this ->values [$ id ]] = self ::$ valuesCache [$ file ];
128
+ } elseif (\is_array ($ expiresAt = include $ file )) {
129
+ if ($ this ->appendOnly ) {
130
+ self ::$ valuesCache [$ file ] = $ expiresAt ;
131
+ }
132
+
127
133
[$ expiresAt , $ this ->values [$ id ]] = $ expiresAt ;
128
134
} elseif ($ now < $ expiresAt ) {
129
135
$ this ->values [$ id ] = new LazyValue ($ file );
130
136
}
131
137
132
138
if ($ now >= $ expiresAt ) {
133
- unset($ this ->values [$ id ], $ missingIds [$ k ]);
139
+ unset($ this ->values [$ id ], $ missingIds [$ k ], self :: $ valuesCache [ $ file ] );
134
140
}
135
141
} catch (\ErrorException $ e ) {
136
142
unset($ missingIds [$ k ]);
@@ -159,7 +165,13 @@ protected function doHave($id)
159
165
$ file = $ this ->files [$ id ] ?? $ this ->files [$ id ] = $ this ->getFile ($ id );
160
166
$ getExpiry = true ;
161
167
162
- if (\is_array ($ expiresAt = include $ file )) {
168
+ if (isset (self ::$ valuesCache [$ file ])) {
169
+ [$ expiresAt , $ value ] = self ::$ valuesCache [$ file ];
170
+ } elseif (\is_array ($ expiresAt = include $ file )) {
171
+ if ($ this ->appendOnly ) {
172
+ self ::$ valuesCache [$ file ] = $ expiresAt ;
173
+ }
174
+
163
175
[$ expiresAt , $ value ] = $ expiresAt ;
164
176
} elseif ($ this ->appendOnly ) {
165
177
$ value = new LazyValue ($ file );
@@ -211,12 +223,14 @@ protected function doSave(array $values, $lifetime)
211
223
$ value = var_export ($ value , true );
212
224
}
213
225
214
- if (!$ isStaticValue ) {
226
+ if ($ isStaticValue ) {
227
+ $ value = "<?php return [ {$ expiry }, {$ value }]; \n" ;
228
+ } elseif ($ this ->appendOnly ) {
229
+ $ value = "<?php return [ {$ expiry }, static function () { return {$ value }; }]; \n" ;
230
+ } else {
215
231
// We cannot use a closure here because of https://bugs.php.net/76982
216
232
$ value = str_replace ('\Symfony\Component\VarExporter\Internal \\' , '' , $ value );
217
233
$ value = "<?php \n\nnamespace Symfony\Component\VarExporter\Internal; \n\nreturn \$getExpiry ? {$ expiry } : {$ value }; \n" ;
218
- } else {
219
- $ value = "<?php return [ {$ expiry }, {$ value }]; \n" ;
220
234
}
221
235
222
236
$ file = $ this ->files [$ key ] = $ this ->getFile ($ key , true );
@@ -227,6 +241,7 @@ protected function doSave(array $values, $lifetime)
227
241
@opcache_invalidate ($ file , true );
228
242
@opcache_compile_file ($ file );
229
243
}
244
+ unset(self ::$ valuesCache [$ file ]);
230
245
}
231
246
232
247
if (!$ ok && !is_writable ($ this ->directory )) {
@@ -260,6 +275,8 @@ protected function doDelete(array $ids)
260
275
261
276
protected function doUnlink ($ file )
262
277
{
278
+ unset(self ::$ valuesCache [$ file ]);
279
+
263
280
if (self ::isSupported ()) {
264
281
@opcache_invalidate ($ file , true );
265
282
}
0 commit comments