generated from Nodarx/template
feat: implement meta and content cache
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -54,29 +54,38 @@ class CollectionResource extends CollectionMutableAbstract
|
||||
return $this;
|
||||
}
|
||||
|
||||
// ── Store (MongoDB cache) ────────────────────────────────────────────────
|
||||
// ── Cache (meta store) ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Serialise to a MongoDB document.
|
||||
* Serialise to a meta store document.
|
||||
*
|
||||
* The caller must inject the service UUID as `sid` before persisting.
|
||||
* The store adds the key fields it owns (sid, tid).
|
||||
*/
|
||||
public function toStore(): array
|
||||
public function toCacheMeta(): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->data,
|
||||
[
|
||||
'name' => $this->data['identifier'],
|
||||
'properties' => $this->getProperties()->toStore(),
|
||||
],
|
||||
);
|
||||
return [
|
||||
'name' => (string) $this->data[static::PROPERTY_IDENTIFIER],
|
||||
'parent' => $this->data[static::PROPERTY_COLLECTION] ?? null,
|
||||
'signature' => $this->data[static::PROPERTY_SIGNATURE] ?? null,
|
||||
'properties' => $this->getProperties()->toCacheMeta(),
|
||||
];
|
||||
}
|
||||
|
||||
public function fromStore(array $data): static
|
||||
/**
|
||||
* Restore from a meta store document.
|
||||
*
|
||||
* Only the resource's own fields are read; store keys and harmonization state
|
||||
* on the same document are ignored.
|
||||
*/
|
||||
public function fromCacheMeta(array $data): static
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data[static::PROPERTY_IDENTIFIER] = (string) $data['name'];
|
||||
$this->data[static::PROPERTY_COLLECTION] = $data['parent'] ?? null;
|
||||
if (isset($data['signature'])) {
|
||||
$this->data[static::PROPERTY_SIGNATURE] = $data['signature'];
|
||||
}
|
||||
if (isset($data['properties'])) {
|
||||
$this->getProperties()->fromStore($data['properties']);
|
||||
$this->getProperties()->fromCacheMeta((array) $data['properties']);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user