/**
  * Wrapper for DB_DataObject's static lookup using memcached
  * as backing instead of an in-process cache array.
  *
  * @param string $cls classname of object type to load
  * @param mixed $k key field name, or value for primary key
  * @param mixed $v key field value, or leave out for primary key lookup
  * @return mixed Memcached_DataObject subtype or false
  */
 function &staticGet($cls, $k, $v = null)
 {
     if (is_null($v)) {
         $v = $k;
         $keys = self::pkeyCols($cls);
         if (count($keys) > 1) {
             // FIXME: maybe call pkeyGet() ourselves?
             throw new Exception('Use pkeyGet() for compound primary keys');
         }
         $k = $keys[0];
     }
     $i = Memcached_DataObject::getcached($cls, $k, $v);
     if ($i === false) {
         // false == cache miss
         $i = DB_DataObject::factory($cls);
         if (empty($i)) {
             $i = false;
             return $i;
         }
         $result = $i->get($k, $v);
         if ($result) {
             // Hit!
             $i->encache();
         } else {
             // save the fact that no such row exists
             $c = self::memcache();
             if (!empty($c)) {
                 $ck = self::cachekey($cls, $k, $v);
                 $c->set($ck, null);
             }
             $i = false;
         }
     }
     return $i;
 }
 /**
  * Wrapper for DB_DataObject's static lookup using memcached
  * as backing instead of an in-process cache array.
  *
  * @param string $cls classname of object type to load
  * @param mixed $k key field name, or value for primary key
  * @param mixed $v key field value, or leave out for primary key lookup
  * @return mixed Memcached_DataObject subtype or false
  */
 function &staticGet($cls, $k, $v = null)
 {
     if (is_null($v)) {
         $v = $k;
         # XXX: HACK!
         $i = new $cls();
         $keys = $i->keys();
         $k = $keys[0];
         unset($i);
     }
     $i = Memcached_DataObject::getcached($cls, $k, $v);
     if ($i === false) {
         // false == cache miss
         $i = DB_DataObject::factory($cls);
         if (empty($i)) {
             $i = false;
             return $i;
         }
         $result = $i->get($k, $v);
         if ($result) {
             // Hit!
             $i->encache();
         } else {
             // save the fact that no such row exists
             $c = self::memcache();
             if (!empty($c)) {
                 $ck = self::cachekey($cls, $k, $v);
                 $c->set($ck, null);
             }
             $i = false;
         }
     }
     return $i;
 }
 function &staticGet($cls, $k, $v = null)
 {
     if (is_null($v)) {
         $v = $k;
         # XXX: HACK!
         $i = new $cls();
         $keys = $i->keys();
         $k = $keys[0];
         unset($i);
     }
     $i = Memcached_DataObject::getcached($cls, $k, $v);
     if ($i) {
         return $i;
     } else {
         $i = DB_DataObject::staticGet($cls, $k, $v);
         if ($i) {
             $i->encache();
         }
         return $i;
     }
 }