]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Memcached_DataObject.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / classes / Memcached_DataObject.php
index 9c92003e5c1ec505afcd4ce1d64b1352faf5289a..e1610c56b214e34205c380dc1c187d2453c3c0a2 100644 (file)
@@ -156,6 +156,44 @@ class Memcached_DataObject extends Safe_DataObject
        
        return $result;
     }
+    
+    function listGet($cls, $keyCol, $keyVals)
+    {
+       $result = array_fill_keys($keyVals, array());
+       
+       $toFetch = array();
+       
+       foreach ($keyVals as $keyVal) {
+           $l = self::cacheGet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal));
+           if ($l !== false) {
+               $result[$keyVal] = $l;
+           } else {
+               $toFetch[] = $keyVal;
+           }
+       }
+        
+        if (count($toFetch) > 0) {
+               $i = DB_DataObject::factory($cls);
+               if (empty($i)) {
+                       throw new Exception(_('Cannot instantiate class ' . $cls));
+               }
+                       $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
+                       if ($i->find()) {
+                               while ($i->fetch()) {
+                                       $copy = clone($i);
+                                       $copy->encache();
+                                       $result[$i->$keyCol][] = $copy;
+                               }
+                       }        
+               foreach ($toFetch as $keyVal)
+               {
+                       self::cacheSet(sprintf("%s:list:%s:%s", $cls, $keyCol, $keyVal),
+                                                  $result[$keyVal]);   
+               }      
+        }
+       
+       return $result;        
+    }
 
        function columnType($columnName)
        {