1 | <?php |
||
17 | class CachingLoader extends CachingLoaderDecorator |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var string $identifier |
||
22 | */ |
||
23 | protected $identifier; |
||
24 | |||
25 | /** |
||
26 | * @var CollectionInterface $cache |
||
27 | */ |
||
28 | protected $cache; |
||
29 | |||
30 | /** |
||
31 | * @var ObjectIdentifier |
||
32 | */ |
||
33 | private $object_identifier; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * CachingLoader constructor. |
||
38 | * |
||
39 | * @param LoaderDecoratorInterface $loader |
||
40 | * @param CollectionInterface $cache |
||
41 | * @param ObjectIdentifier $object_identifier |
||
42 | * @param string $identifier |
||
43 | * @throws InvalidDataTypeException |
||
44 | */ |
||
45 | public function __construct( |
||
46 | LoaderDecoratorInterface $loader, |
||
47 | CollectionInterface $cache, |
||
48 | ObjectIdentifier $object_identifier, |
||
49 | $identifier = '' |
||
50 | ) { |
||
51 | parent::__construct($loader); |
||
52 | $this->cache = $cache; |
||
53 | $this->object_identifier = $object_identifier; |
||
54 | $this->setIdentifier($identifier); |
||
55 | if ($this->identifier !== '') { |
||
56 | // to only clear this cache, and assuming an identifier has been set, simply do the following: |
||
57 | // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
||
58 | // where "IDENTIFIER" = the string that was set during construction |
||
59 | add_action( |
||
60 | "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
||
61 | array($this, 'reset') |
||
62 | ); |
||
63 | } |
||
64 | // to clear ALL caches, simply do the following: |
||
65 | // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
||
66 | add_action( |
||
67 | 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
||
68 | array($this, 'reset') |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | public function identifier() |
||
77 | { |
||
78 | return $this->identifier; |
||
79 | } |
||
80 | |||
81 | |||
82 | /** |
||
83 | * @param string $identifier |
||
84 | * @throws InvalidDataTypeException |
||
85 | */ |
||
86 | private function setIdentifier($identifier) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * @param FullyQualifiedName|string $fqcn |
||
97 | * @param mixed $object |
||
98 | * @return bool |
||
99 | * @throws InvalidArgumentException |
||
100 | */ |
||
101 | public function share($fqcn, $object) |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @param FullyQualifiedName|string $fqcn |
||
120 | * @param array $arguments |
||
121 | * @param bool $shared |
||
122 | * @param array $interfaces |
||
123 | * @return mixed |
||
124 | */ |
||
125 | public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
||
149 | |||
150 | |||
151 | /** |
||
152 | * empties cache and calls reset() on loader if method exists |
||
153 | */ |
||
154 | public function reset() |
||
159 | |||
160 | |||
161 | /** |
||
162 | * unsets and detaches ALL objects from the cache |
||
163 | * |
||
164 | * @since $VID:$ |
||
165 | */ |
||
166 | public function clearCache() |
||
170 | } |
||
171 |