1 | <?php |
||
12 | class Cache |
||
13 | { |
||
14 | /** |
||
15 | * All models currently loaded in memory. |
||
16 | * Is an associative array of model type keys to model objects. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private $models = []; |
||
21 | |||
22 | /** |
||
23 | * Gets all models in the memory cache. |
||
24 | * Will be keyed by model type. |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | public function getAll() |
||
32 | |||
33 | /** |
||
34 | * Gets all models in the memory cache for a specific type. |
||
35 | * |
||
36 | * @param string $typeKey |
||
37 | * @return Model[] |
||
38 | */ |
||
39 | public function getAllForType($typeKey) |
||
46 | |||
47 | /** |
||
48 | * Clears all models in the memory cache for a specific type. |
||
49 | * |
||
50 | * @param string $typeKey |
||
51 | * @return self |
||
52 | */ |
||
53 | public function clearType($typeKey) |
||
60 | |||
61 | /** |
||
62 | * Clears all models in the memory cache. |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | public function clearAll() |
||
71 | |||
72 | /** |
||
73 | * Pushes a model into the memory cache. |
||
74 | * |
||
75 | * @param Model $model |
||
76 | * @return self |
||
77 | */ |
||
78 | public function push(Model $model) |
||
83 | |||
84 | /** |
||
85 | * Removes a model from the memory cache, based on type and identifier. |
||
86 | * |
||
87 | * @param string $typeKey |
||
88 | * @param string $identifier |
||
89 | * @return self |
||
90 | */ |
||
91 | public function remove($typeKey, $identifier) |
||
98 | |||
99 | /** |
||
100 | * Gets a model from the memory cache, based on type and identifier. |
||
101 | * |
||
102 | * @param string $typeKey |
||
103 | * @param string $identifier |
||
104 | * @return Model|null |
||
105 | */ |
||
106 | public function get($typeKey, $identifier) |
||
114 | |||
115 | /** |
||
116 | * Determines if a model exists in the memory cache, based on type and identifier. |
||
117 | * |
||
118 | * @param string $typeKey |
||
119 | * @param string $identifier |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function has($typeKey, $identifier) |
||
126 | } |
||
127 |