1 | <?php |
||
9 | class CachedCategoryResolver implements CategoryResolverInterface |
||
10 | { |
||
11 | const CACHE_KEY_RESOLVE_BY_URL_KEY = 'resolve_category_by_ulkey'; |
||
12 | const CACHE_KEY_RESOLVE_BY_ID = 'resolve_category_by_id'; |
||
13 | const CACHE_KEY_RESOLVE_PARENT_IDS = 'resolve_category_parent_ids'; |
||
14 | |||
15 | /** |
||
16 | * @var CategoryResolverInterface |
||
17 | */ |
||
18 | private $categoryResolver; |
||
19 | |||
20 | /** |
||
21 | * @var CacheInterface |
||
22 | */ |
||
23 | private $cache; |
||
24 | |||
25 | /** |
||
26 | * @param CategoryResolverInterface $categoryResolver |
||
27 | * @param CacheInterface $cache |
||
28 | */ |
||
29 | public function __construct(CategoryResolverInterface $categoryResolver, CacheInterface $cache) |
||
34 | |||
35 | /** |
||
36 | * @param string $urlKey |
||
37 | * @param int $storeId |
||
38 | * @param int $parentId |
||
39 | * |
||
40 | * @return EntityData |
||
41 | */ |
||
42 | public function resolveByUrlKey(string $urlKey, int $storeId, int $parentId) : EntityData |
||
43 | { |
||
44 | $cacheKey = implode('_', [self::CACHE_KEY_RESOLVE_BY_URL_KEY, $urlKey, $storeId, $parentId]); |
||
45 | |||
46 | if (!$this->cache->has($cacheKey)) { |
||
47 | $data = $this->categoryResolver->resolveByUrlKey($urlKey, $storeId, $parentId); |
||
48 | $this->cache->set($cacheKey, $data); |
||
49 | } |
||
50 | |||
51 | return $this->cache->get($cacheKey); |
||
52 | } |
||
53 | |||
54 | public function resolveAllByUrlKey(string $urlKey, int $storeId, int $parentId) : array |
||
58 | |||
59 | /** |
||
60 | * @param int $categoryId |
||
61 | * @param int $storeId |
||
62 | * |
||
63 | * @return EntityData |
||
64 | */ |
||
65 | public function resolveById(int $categoryId, int $storeId) : EntityData |
||
76 | |||
77 | /** |
||
78 | * @param int $categoryId |
||
79 | * @param int $storeId |
||
80 | * |
||
81 | * @return int[] |
||
82 | */ |
||
83 | public function resolveParentIds(int $categoryId, int $storeId) : array |
||
94 | } |
||
95 |