0

Which is the most efficient way to load desired model data if you have the flexibility to use any of the available methods?

My guess is via factory and load due to my assumption that the repositories are state-less and a single selection would be faster than filtering a collection down. However, with all of the caching and other optimizations I would like a confirmation.

1

You should use the repository Interface defined for the particular model.

for example if you want to load a product use productRepositoryInterface methods.

you should pass the productRepositoryInterface in your construct.

and get the model using.

$product = $this->productRepository->getById($productId);

Now, This will return you the product if it already exist in cache directly from cache Or it will load from database.

  • You made no mention of efficiency? – LM_Fielding Apr 29 '17 at 20:36
  • If you read the last line, it explains why this is an efficient method. – Pankaj Bhope May 2 '17 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.