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

Multi get for second level cache (Doctrine Cache related)

    Details

      Description

      Hi every body!

      I'm developing an application that is highly based on doctrine second-level cache feature.
      Using memcache or redis as cache back-end, doctrine have to query thousand times for the cached values (especially on one-to-many and many-to-many associations).
      This introduces a lot of latency (and network traffic)...

      I'm thinking to add to Doctrine\Common\Cache\Cache interface a method fetchMulti(array $keys) that fetches multiple items in one call. In this way doctrine orm can ask for many items with just one call (for example, here https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php#L84 this feature can be very useful).

      I have made some real-world tests and it can reduce highly the number of total queries (my app runs 190 cache requests instead of 900 cache requests)

      Many vendors (memcache, redis, apc ecc) already offer this functionality, but with doctrine-cache we can't use it...

      I'm going to implement this feature. Can it be accepted as a pull request?

      It may be BC breaking:

      • it can be implemented adding a method inside Doctrine\Common\Cache\Cache interface (more BC breaking but more clean and elegant)
      • it can be implemented adding an interface Doctrine\Common\Cache\MultiCache and later CacheProvider can implement it (less BC breaking)

        Issue Links

          Activity

          Hide
          ocramius Marco Pivetta added a comment -

          Adding a method to Doctrine\Common\Cache\Cache is not viable because of BC - a new interface would be ok

          Show
          ocramius Marco Pivetta added a comment - Adding a method to Doctrine\Common\Cache\Cache is not viable because of BC - a new interface would be ok
          Hide
          goetas Asmir Mustafic added a comment - - edited

          ok, i agree with you.
          But this forces me to check always here https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php#L95 if $this->cache is instance of MultiCache

          Show
          goetas Asmir Mustafic added a comment - - edited ok, i agree with you. But this forces me to check always here https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php#L95 if $this->cache is instance of MultiCache
          Hide
          ocramius Marco Pivetta added a comment -

          Asmir Mustafic or you build a MultiCacheRegion

          Show
          ocramius Marco Pivetta added a comment - Asmir Mustafic or you build a MultiCacheRegion
          Hide
          goetas Asmir Mustafic added a comment -

          It can be a good approach. I will try it.
          I'm thinking to provide a default implementation of fetchMulti directly inside CacheProvider that internally loops over each key and call CacheProvider::fetch($id) to fetch its value.
          Later i will overwrite this behavior inside vendor specific driver (ApcCache, RedisCache...)

          Show
          goetas Asmir Mustafic added a comment - It can be a good approach. I will try it. I'm thinking to provide a default implementation of fetchMulti directly inside CacheProvider that internally loops over each key and call CacheProvider::fetch($id) to fetch its value. Later i will overwrite this behavior inside vendor specific driver ( ApcCache , RedisCache ...)
          Hide
          ocramius Marco Pivetta added a comment -

          Solved in DDC-2982

          Show
          ocramius Marco Pivetta added a comment - Solved in DDC-2982

            People

            • Assignee:
              ocramius Marco Pivetta
              Reporter:
              goetas Asmir Mustafic
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: