Jira issue originally created by user goetas:
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:
Comment created by @ocramius:
Adding a method to Doctrine\Common\Cache\Cache is not viable because of BC - a new interface would be ok
Comment created by goetas:
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
[~goetas] or you build a MultiCacheRegion
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...)
Solved in DDC-2982
Issue was closed with resolution "Fixed"