feat: implement meta and content cache

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-29 19:45:00 -04:00
parent e5e76351a5
commit d28800a04e
8 changed files with 715 additions and 22 deletions
+23 -14
View File
@@ -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;
}