88use TiMacDonald \JsonApi \JsonApiResource ;
99use TiMacDonald \JsonApi \JsonApiResourceCollection ;
1010
11+ /**
12+ * @internal
13+ * @todo can we get rid of this?
14+ */
1115trait Caching
1216{
13- /**
14- * @internal
15- */
16- private string |null $ idCache = null ;
17-
18- /**
19- * @internal
20- */
21- private string |null $ typeCache = null ;
22-
23- /**
24- * @internal
25- *
26- * @var Collection<string, JsonApiResource|JsonApiResourceCollection>|null
27- */
28- private Collection |null $ requestedRelationshipsCache = null ;
29-
3017 /**
3118 * @internal
3219 * @infection-ignore-all
@@ -35,51 +22,14 @@ trait Caching
3522 */
3623 public function flush ()
3724 {
38- $ this ->idCache = null ;
39-
40- $ this ->typeCache = null ;
41-
42- if ($ this ->requestedRelationshipsCache !== null ) {
43- $ this ->requestedRelationshipsCache ->each (fn (JsonApiResource |JsonApiResourceCollection $ relation ) => $ relation ->flush ());
44- }
25+ // TODO can we just let this garbage collect?
26+ $ this ->requestedRelationshipsCache ?->each(fn (JsonApiResource |JsonApiResourceCollection $ relation ) => $ relation ->flush ());
4527
4628 $ this ->requestedRelationshipsCache = null ;
47- }
4829
49- /**
50- * @internal
51- * @infection-ignore-all
52- *
53- * @param (callable(): string) $callback
54- * @return string
55- */
56- private function rememberId (callable $ callback )
57- {
58- return $ this ->idCache ??= $ callback ();
59- }
60-
61- /**
62- * @internal
63- * @infection-ignore-all
64- *
65- * @param (callable(): string) $callback
66- * @return string
67- */
68- private function rememberType (callable $ callback )
69- {
70- return $ this ->typeCache ??= $ callback ();
71- }
30+ $ this ->idCache = null ;
7231
73- /**
74- * @internal
75- * @infection-ignore-all
76- *
77- * @param (callable(): Collection<string, JsonApiResource|JsonApiResourceCollection>) $callback
78- * @return Collection<string, JsonApiResource|JsonApiResourceCollection>
79- */
80- private function rememberRequestRelationships (callable $ callback )
81- {
82- return $ this ->requestedRelationshipsCache ??= $ callback ();
32+ $ this ->typeCache = null ;
8333 }
8434
8535 /**
@@ -89,6 +39,7 @@ private function rememberRequestRelationships(callable $callback)
8939 */
9040 public function requestedRelationshipsCache ()
9141 {
42+ // TODO can we remove this if we ditch caching? Only here for tests.
9243 return $ this ->requestedRelationshipsCache ;
9344 }
9445}
0 commit comments