Repositories

When creating a page it's highly recommended to work from Repository classes because it has build in cache. You should invalidate cache only when you update or remove item from the model by using the following methods:


PHP:
public function updateEntry(Model $model);
// By using updateEntry, you should provide Illuminate's updated/saved Model in function parameter!
public function removeEntry(Model $model);
// you should provide the model instance from illuminate.

When creating repository, your repository should be placed in App\Http\Repository directory and should be names as suffix Repository, plus should extend AbstractRepository class and should implement $cachekey protected class variable and getModel() method and should return it's Illuminate's Model.

Available methods from Abstracted Repository:
PHP:
public function getCollection();
/**
 The above function will return RepositoryCollections from cache if exists, if not, they will
 be fetched from database and stored in cache then displayed. Each RepositoryCollection displays
 Illuminate's Model.
*/
public function searchInCache(array $conditions);
/**
The above method will search for RepositoryCollections using conditions in array, Note: you should not set operator in array.
If they doesn't exist in the cache, empty array will be returned.
*/
public function findOne($primaryKey, bool $usecache = true);
/**
The above method will attempt to get RepositoryCollection from it's primary key if found in cache
if not, the method will fetch it from database, store it in the cache, and display the Illuminate's Model.
All Illuminate's Model methods are available when called this!
If bool $useCache is false, u will get the record from the database!
*/

public function findOneWhere(string $column, string $value, bool $fromCache = true);
/**
If $fromCache is true, the repository will search within cache by its column and value if exists, if not
will try to find in database if exist, will add in cache, then display the Illuminate's model.
*/
public function findManyWhere(array $conditions, bool $fromCache = true);
/**
Find many entries by their column keys from cache storage, if they don't exist in cache, then query the database and store them in cache
If $fromCache is false, u will get the record from database!
*/
public function createEntry(Model $model);
/**
Will update the cache will new Illuminate's model.
*/
public function findMany(array $primaryKeys = []);
/**
 Will search in cache using Model's primary keys and return array of RepositoryCollections
 If they doesn't exist the repository will attempt to fetch from the database, store in the cache and then display the records.
*/
 

Attachments

  • 1703323364392.png
    1703323364392.png
    132.2 KB · Views: 5
Top