1 | <?php |
||
11 | class CachingDecorator implements Decorator |
||
12 | { |
||
13 | /** |
||
14 | * @var CommandBus |
||
15 | */ |
||
16 | private $innerBus; |
||
17 | /** |
||
18 | * @var CacheItemPoolInterface |
||
19 | */ |
||
20 | private $cache; |
||
21 | |||
22 | /** |
||
23 | * CachingDecorator constructor. |
||
24 | * @param CacheItemPoolInterface $cache |
||
25 | */ |
||
26 | public function __construct(CacheItemPoolInterface $cache) |
||
30 | |||
31 | /** |
||
32 | * @inheritdoc |
||
33 | */ |
||
34 | public function setInnerBus(CommandBus $bus) |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public function execute(Command $command) |
||
59 | |||
60 | /** |
||
61 | * Create a new cache item to be persisted. |
||
62 | * |
||
63 | * @param CacheableCommand $command |
||
64 | * @param mixed $value |
||
65 | * @return CacheItem |
||
66 | */ |
||
67 | private function createCacheItem(CacheableCommand $command, $value) |
||
75 | |||
76 | /** |
||
77 | * Create the key to be used when saving this item to the cache pool. |
||
78 | * |
||
79 | * The cache item key is taken as a the (string) serialized command, to ensure the return value is unique |
||
80 | * depending on the command properties; that serialized string is then md5'd to ensure it doesn't |
||
81 | * overflow any string length limits the implementing CacheItemPoolInterface library has. |
||
82 | * |
||
83 | * @param CacheableCommand $command |
||
84 | * @return string |
||
85 | */ |
||
86 | private function createCacheKey(CacheableCommand $command) |
||
90 | } |
||
91 |