1 | <?php |
||
13 | class CachedProductResolver implements ProductResolverInterface |
||
14 | { |
||
15 | const CACHE_KEY_RESOLVE_BY_URL_KEY = 'resolve_product_by_ulkey'; |
||
16 | const CACHE_KEY_RESOLVE_BY_ID = 'resolve_product_by_id'; |
||
17 | const CACHE_KEY_RESOLVE_CATEGORIES = 'resolve_product_categories'; |
||
18 | |||
19 | /** |
||
20 | * @var ProductResolverInterface |
||
21 | */ |
||
22 | private $productResolver; |
||
23 | |||
24 | /** |
||
25 | * @var CacheInterface |
||
26 | */ |
||
27 | private $cache; |
||
28 | |||
29 | /** |
||
30 | * @param ProductResolverInterface $productResolver |
||
31 | * @param CacheInterface $cache |
||
32 | */ |
||
33 | public function __construct(ProductResolverInterface $productResolver, CacheInterface $cache) |
||
38 | |||
39 | /** |
||
40 | * @param string $urlKey |
||
41 | * @param int $storeId |
||
42 | * |
||
43 | * @return EntityData |
||
44 | */ |
||
45 | public function resolveByUrlKey(string $urlKey, int $storeId) : EntityData |
||
46 | { |
||
47 | $cacheKey = implode('_', [self::CACHE_KEY_RESOLVE_BY_URL_KEY, $urlKey, $storeId]); |
||
48 | |||
49 | if (!$this->cache->has($cacheKey)) { |
||
50 | $data = $this->productResolver->resolveByUrlKey($urlKey, $storeId); |
||
51 | $this->cache->set($cacheKey, $data); |
||
52 | } |
||
53 | |||
54 | return $this->cache->get($cacheKey); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $urlKey |
||
59 | * @param int $storeId |
||
60 | * |
||
61 | * @return EntityData[] |
||
62 | */ |
||
63 | public function resolveAllByUrlKey(string $urlKey, int $storeId) : array |
||
67 | |||
68 | /** |
||
69 | * @param int $productId |
||
70 | * @param int $storeId |
||
71 | * |
||
72 | * @return EntityData |
||
73 | */ |
||
74 | public function resolveById(int $productId, int $storeId) : EntityData |
||
85 | |||
86 | /** |
||
87 | * @param int $productId |
||
88 | * @param int $storeId |
||
89 | * |
||
90 | * @return int[] |
||
91 | */ |
||
92 | public function resolveCategoryIds(int $productId, int $storeId) : array |
||
103 | } |
||
104 |