77/**
88 * @template TSource of object
99 * @template TTarget of object
10- * @template TContext of object |null
10+ * @template TContext of CacheAwareContext |null
1111 *
1212 * @implements Cache<TSource, TTarget, TContext>
1313 */
@@ -19,20 +19,28 @@ final class InMemoryCache implements Cache
1919 private array $ targets = [];
2020
2121 /**
22- * @param CacheKeyFactory<TSource, TContext > $keyFactory
22+ * @param CacheKeyFactory<TSource> $keyFactory
2323 */
2424 public function __construct (
2525 private CacheKeyFactory $ keyFactory ,
2626 ) {
2727 }
2828
29- public function get (object $ source , ?object $ ctx = null ): ?object
29+ public function get (object $ source , ?CacheAwareContext $ ctx = null ): ?object
3030 {
31- return $ this ->targets [$ this ->keyFactory -> createFor ($ source , $ ctx )] ?? null ;
31+ return $ this ->targets [$ this ->createKey ($ source , $ ctx )] ?? null ;
3232 }
3333
34- public function set (object $ source , object $ target , ?object $ ctx = null ): void
34+ public function set (object $ source , object $ target , ?CacheAwareContext $ ctx = null ): void
3535 {
36- $ this ->targets [$ this ->keyFactory ->createFor ($ source , $ ctx )] = $ target ;
36+ $ this ->targets [$ this ->createKey ($ source , $ ctx )] = $ target ;
37+ }
38+
39+ /**
40+ * @param TSource $source
41+ */
42+ private function createKey (object $ source , ?CacheAwareContext $ ctx = null ): string
43+ {
44+ return $ this ->keyFactory ->createFor ($ source ) . $ ctx ?->getHash();
3745 }
3846}
0 commit comments