class cached_item_repository implements item_repository_interface

internal  
 

Cache Decorator for the Item Repository.

Wraps an item_repository_interface to provide transparent MUC (Moodle Universal Cache) caching for EAV items and their metadata, reducing database N+1 loads and hydration penalty.

Constants

private CACHE_AREA

Methods

__construct(item_repository_interface $repository)

Constructor mapping the inner repository instance via Depedency Injection.

create(item_dto_interface $dto)

Create a new item from a DTO.

item_interface|null
find_by_id(int $id)

Find an item by ID.

update(item_dto_interface $dto)

Update an existing item from a DTO.

void
delete(int $id)

Delete an item and all related metadata.

array
get_metadata(int $itemid)

Get all metadata associated with an item.

void
save_metadata(int $itemid, array $metadata)

Save (insert/update) metadata entries.

array
find_by_metadata(string $key, string $value)

Search items by metadata key/value pair.

array
find_by_type(string $type)

Find all items of a given TYPE.

Details

at line 43
__construct(item_repository_interface $repository)

Constructor mapping the inner repository instance via Depedency Injection.

Parameters

item_repository_interface $repository

The actual repository doing DB I/O

at line 50
item_interface create(item_dto_interface $dto)

Create a new item from a DTO.

Must be atomic: Item + Metadata in a single transaction.

Parameters

item_dto_interface $dto

Return Value

item_interface

Exceptions

JsonException

at line 63
item_interface|null find_by_id(int $id)

Find an item by ID.

Parameters

int $id

Return Value

item_interface|null

Exceptions

dml_exception

at line 73
item_interface update(item_dto_interface $dto)

Update an existing item from a DTO.

Must be atomic: Item + Metadata in a single transaction.

Parameters

item_dto_interface $dto

Return Value

item_interface

Exceptions

moodle_exception

at line 87
void delete(int $id)

Delete an item and all related metadata.

Parameters

int $id

Return Value

void

Exceptions

dml_transaction_exception

at line 106
array get_metadata(int $itemid)

Get all metadata associated with an item.

Parameters

int $itemid

Return Value

array

Exceptions

dml_exception

at line 116
void save_metadata(int $itemid, array $metadata)

Save (insert/update) metadata entries.

Keys not provided must remain untouched.

Parameters

int $itemid
array $metadata

Return Value

void

Exceptions

JsonException

at line 129
array find_by_metadata(string $key, string $value)

Search items by metadata key/value pair.

Parameters

string $key
string $value

Return Value

array

Exceptions

dml_exception

at line 154
array find_by_type(string $type)

Find all items of a given TYPE.

Must use efficient metadata loading to avoid N+1.

Parameters

string $type

Return Value

array

Exceptions

dml_exception