Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2043

Extra cache operation in DBAL\Cache\ResultCacheStatement.php

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      CentOS, PHP 5.3.10

      Description

      This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

      public function closeCursor()
          {
              $this->statement->closeCursor();
              if ($this->emptied && $this->data !== null) {
                  $data = $this->resultCache->fetch($this->cacheKey);
                  if ( ! $data) {
                      $data = array();
                  }
                  $data[$this->realKey] = $this->data;
      
                  $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                  unset($this->data);
              }
          }
      

      We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
      Also, may I ask why is the SQL used as a key in the cached data?

        Activity

        bogdan.albei Bogdan Albei created issue -
        bogdan.albei Bogdan Albei made changes -
        Field Original Value New Value
        Description This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.

        The following should perform the same function:
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = array();
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:
        <pre>
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        </pre>
        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.

        The following should perform the same function:
        <pre>
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = array();
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        </pre>
        bogdan.albei Bogdan Albei made changes -
        Description This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:
        <pre>
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        </pre>
        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.

        The following should perform the same function:
        <pre>
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = array();
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        </pre>
        This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
        stof Christophe Coevoet made changes -
        Description This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
        This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

        {code}
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        {code}

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
        bogdan.albei Bogdan Albei made changes -
        Description This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

        {code}
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        {code}

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
        This is the closeCursor() method in DBAL\Cache\ResultCacheStatement.php:

        {code}
        public function closeCursor()
            {
                $this->statement->closeCursor();
                if ($this->emptied && $this->data !== null) {
                    $data = $this->resultCache->fetch($this->cacheKey);
                    if ( ! $data) {
                        $data = array();
                    }
                    $data[$this->realKey] = $this->data;

                    $this->resultCache->save($this->cacheKey, $data, $this->lifetime);
                    unset($this->data);
                }
            }
        {code}

        We are using Memcache and I noticed an extra GET operation on all cache misses. In the code above I believe the fetch call is not necessary and that the code would do the same without it.
        Also, may I ask why is the SQL used as a key in the cached data?
        Hide
        stof Christophe Coevoet added a comment -

        The SQL is used as a key because it is what identifies the query which is done (well, the statement and the parameters)

        Show
        stof Christophe Coevoet added a comment - The SQL is used as a key because it is what identifies the query which is done (well, the statement and the parameters)
        Hide
        bogdan.albei Bogdan Albei added a comment -

        The cacheKey already identifies the query(or at least it should). Would we have cases where different queries would want to use the same cache key?

        Show
        bogdan.albei Bogdan Albei added a comment - The cacheKey already identifies the query(or at least it should). Would we have cases where different queries would want to use the same cache key?

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={expand=changesets[0:20].revisions[0:29],reviews, query=DDC-2043}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            bogdan.albei Bogdan Albei
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: