99use Symfony \Component \Cache \Adapter \PhpFilesAdapter ;
1010use Tempest \Discovery \Discovery ;
1111use Tempest \Discovery \DiscoveryItems ;
12+ use Tempest \Discovery \DiscoveryLocation ;
1213use Throwable ;
1314
1415use function Tempest \internal_storage_path ;
@@ -32,24 +33,40 @@ public function __construct(
3233 );
3334 }
3435
35- public function restore (string $ className ): ?DiscoveryItems
36+ /**
37+ * @return array<class-string<\Tempest\Discovery\Discovery>, DiscoveryItems>
38+ */
39+ public function restore (DiscoveryLocation $ location ): ?array
3640 {
3741 if (! $ this ->enabled ) {
3842 return null ;
3943 }
4044
4145 return $ this ->pool
42- ->getItem (str_replace ( '\\' , ' _ ' , $ className ) )
46+ ->getItem ($ location -> key )
4347 ->get ();
4448 }
4549
46- public function store (Discovery $ discovery , DiscoveryItems $ discoveryItems ): void
50+ /**
51+ * @param Discovery[] $discoveries
52+ */
53+ public function store (DiscoveryLocation $ location , array $ discoveries ): void
4754 {
48- $ key = str_replace ('\\' , '_ ' , $ discovery ::class);
55+ $ cachedForLocation = [];
56+
57+ foreach ($ discoveries as $ discovery ) {
58+ $ items = $ discovery ->getItems ();
59+
60+ if ($ this ->strategy === DiscoveryCacheStrategy::PARTIAL ) {
61+ $ items = $ items ->onlyVendor ();
62+ }
63+
64+ $ cachedForLocation [$ discovery ::class] = $ items ->getForLocation ($ location );
65+ }
4966
5067 $ item = $ this ->pool
51- ->getItem ($ key )
52- ->set ($ discoveryItems );
68+ ->getItem ($ location -> key )
69+ ->set ($ cachedForLocation );
5370
5471 $ this ->pool ->save ($ item );
5572 }
0 commit comments