I am working on one Drupal 8.3 site. I created my own custom Authentication provider for REST API authorisation.

Following are the "authenticate" method sample code.

   * {@inheritdoc}
  public function authenticate(Request $request) {
      try {

          $uid = 1;// passing 1 for testing.

          $accounts = $this->entityTypeManager->getStorage('user')->loadByProperties(array('uid' => $uid, 'status' => 1));
          $account = reset($accounts);
          if ($account) {
              return $this->entityTypeManager->getStorage('user')->load($uid);
      return [];

My doubt here is "$this->entityTypeManager->getStorage" is getting data from cache table. Or everytime it connect to db and generate response?


load() and loadMultiple() are cached, loadByProperties() is a shortcut for an entity query + load, the entity query is not cached.

Do not use loadByProperties() if you know the entity ID.

  • Really thanks Berdir for explanation. But may you please explain why not to use loadByProperties if knowing entity id. Its not clear this to me. Would you give any reference or more details. – vijay Jul 1 '17 at 17:49
  • because you do a query to get the ids. If you already have the id, you can just use load() or loadMultiple(). – Berdir Jul 3 '17 at 20:30

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.