1 | <?php |
||
22 | final class EntityMap |
||
23 | { |
||
24 | /** |
||
25 | * @var EntityInterface[] |
||
26 | */ |
||
27 | private $entities = []; |
||
28 | |||
29 | /** |
||
30 | * Maximum entity cache size. Null is unlimited. |
||
31 | * |
||
32 | * @var int|null |
||
33 | */ |
||
34 | private $maxSize = null; |
||
35 | |||
36 | /** |
||
37 | * @param int|null $maxSize Set to null to make cache size unlimited. |
||
38 | */ |
||
39 | public function __construct(int $maxSize = null) |
||
43 | |||
44 | /** |
||
45 | * Add Record to entity cache. Primary key value will be used as |
||
46 | * identifier. |
||
47 | * |
||
48 | * Attention, existed entity will be replaced! |
||
49 | * |
||
50 | * @param string $class |
||
51 | * @param string $identity |
||
52 | * @param RecordInterface $entity |
||
53 | * @param bool $ignoreLimit Cache overflow will be ignored. |
||
54 | * |
||
55 | * @return RecordInterface Returns given entity. |
||
56 | * |
||
57 | * @throws CacheException When cache size exceeded. |
||
58 | */ |
||
59 | public function remember( |
||
71 | |||
72 | /** |
||
73 | * Remove entity record from entity cache. Primary key value will be used as identifier. |
||
74 | * |
||
75 | * @param string $class |
||
76 | * @param string $identity |
||
77 | */ |
||
78 | public function forget(string $class, string $identity) |
||
82 | |||
83 | /** |
||
84 | * Check if desired entity was already cached. |
||
85 | * |
||
86 | * @param string $class |
||
87 | * @param string $identity |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function has(string $class, string $identity): bool |
||
95 | |||
96 | /** |
||
97 | * Fetch entity from cache. |
||
98 | * |
||
99 | * @param string $class |
||
100 | * @param string $identity |
||
101 | * |
||
102 | * @return null|mixed |
||
103 | */ |
||
104 | public function get(string $class, string $identity) |
||
112 | |||
113 | /** |
||
114 | * Flush content of entity cache. |
||
115 | */ |
||
116 | public function flushCache() |
||
120 | |||
121 | /** |
||
122 | * Destructing. |
||
123 | */ |
||
124 | public function __destruct() |
||
128 | } |