Answer the question
In order to leave comments, you need to log in
Caching: repository or model?
I have wondered more than once, read the answers on the toaster about this, but have never seen a clear answer. So, the question is: Where is it more correct, from the point of view of architecture (In a Laravel application), to store the caching logic (For example, if there is data in the cache, pull it out, otherwise give the data from the database) in the repository or in the model? It seems like the model is responsible for working with the data, although on the other hand, I heard the opinion that the model is a simple POPO.
Answer the question
In order to leave comments, you need to log in
I wrote my driver 10 years ago and I don't know any problems.
$sth = $db->prepare("SELECT * FROM foo");
$sth->cache("Foo:*");
$sth->execute();
$sth = $db->prepare("SELECT * FROM foo");
$sth->execute();
above the repository. I did the following: I write a repository, its interface, then through the container service I bind the interface to the implementation. Later, another code-code-code, then after a while I already write the cache layer and all the caching logic. The caching class inherits the same interface and, when written, is substituted into the service container instead of the current implementation. You can put the caching layer even higher, everything depends on your architecture (therefore, there will be no unequivocal answer either), but I personally don’t see the point below, maybe I just didn’t come across examples when it was required. And the architecture within Laravel is not clearly defined. There are some tools described in the documentation, but you can build the architecture in the way that seems most correct to you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question