File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939abstract class AsyncKernel extends Kernel implements CompilerPassInterface
4040{
4141 private string $ uid ;
42+ private bool $ forceCacheUsage = false ;
43+
44+ /**
45+ * @return void
46+ */
47+ public function forceCacheUsage ()
48+ {
49+ $ this ->forceCacheUsage = true ;
50+ }
4251
4352 /**
4453 * {@inheritdoc}
@@ -48,7 +57,7 @@ public function boot()
4857 if (!$ this ->booted ) {
4958 $ this ->uid = $ this ->generateUID ();
5059
51- if (($ _ENV ['DRIFT_CACHE_ENABLED ' ] ?? '0 ' ) !== '1 ' ) {
60+ if (! $ this -> forceCacheUsage && ($ _ENV ['DRIFT_CACHE_ENABLED ' ] ?? '0 ' ) !== '1 ' ) {
5261 $ fs = new Filesystem ();
5362 // AsyncKernel loads the container only once when it loads. Storing it in the filesystem is not for cache purposes
5463 // but more for using the same loading process as Kernel class use.
Original file line number Diff line number Diff line change @@ -38,7 +38,25 @@ public function testWithoutCache()
3838 unset($ _ENV ['DRIFT_CACHE_ENABLED ' ]);
3939 }
4040
41- public function testWithCache ()
41+ public function testWithCacheFromStaticSetting ()
42+ {
43+ static ::$ kernel = static ::getKernel ();
44+ static ::$ kernel ->forceCacheUsage ();
45+ static ::$ kernel ->boot ();
46+
47+ $ cacheDir = self ::$ kernel ->getCacheDir ();
48+ $ firstKernelCacheCreationTime = lstat ($ cacheDir )['ctime ' ];
49+ sleep (1 );
50+
51+ static ::$ kernel = static ::getKernel ();
52+ static ::$ kernel ->forceCacheUsage ();
53+ $ cacheDir = self ::$ kernel ->getCacheDir ();
54+ $ secondKernelCacheCreationTime = lstat ($ cacheDir )['ctime ' ];
55+
56+ $ this ->assertEquals ($ firstKernelCacheCreationTime , $ secondKernelCacheCreationTime );
57+ }
58+
59+ public function testWithCacheWithEnv ()
4260 {
4361 $ _ENV ['DRIFT_CACHE_ENABLED ' ] = '1 ' ;
4462 static ::setUpBeforeClass ();
You can’t perform that action at this time.
0 commit comments