Example #1
0
 public function identifiers(array $affiliations)
 {
     $cache = $this->affiliationCache();
     $cache = new Cacher\Callback($cache, array('callback' => array($this->core, __FUNCTION__), 'timeout' => 300, 'cache_missing' => TRUE));
     $res = $cache->get($affiliations);
     return $res;
 }
 /**
  * grab a list of auctions by id from the cache and repopulate missing records from the db.
  */
 public function fetch(array $ids, $lock = FALSE)
 {
     if ($lock) {
         return $this->core()->fetch($ids, $lock);
     }
     $cache = $this->cache();
     $timeout = $this->cacheTimeout();
     if (count($ids) < 1) {
         return array();
     }
     if ($this->refresh) {
         $rows = $this->core->fetch($ids, FALSE);
         foreach ($rows as $k => $v) {
             $cache->set($k, $v, $timeout);
         }
         return $rows;
     }
     $options = array('callback' => array($this->core, 'fetch'), 'method' => 'add', 'timeout' => $timeout, 'cache_missing' => TRUE);
     $cache = new Store\Callback($cache, $options);
     $result = $cache->get($ids);
     if (!is_array($result)) {
         $result = array();
     }
     return $result;
 }
Example #3
0
 protected function multiGet(array $ids)
 {
     // add the callback handler for populating missing rows from core.
     $options = array('callback' => array($this->core, 'get'), 'missing' => TRUE, 'method' => 'add', 'timeout' => $this->ttl);
     $cache = new Store\Callback($this->cache, $options);
     return $cache->get($ids);
 }
Example #4
0
 public function pathById($input)
 {
     $core = $this->core;
     $cache = new Store\Callback($this->cache(), array('callback' => function ($input) use($core) {
         return $core->pathById($input);
     }, 'timeout' => $this->ttl, 'cache_missing' => TRUE));
     return $cache->get($input);
 }
Example #5
0
 public function byName($request)
 {
     $core = $this->core;
     $cb = function ($request) use($core) {
         return $core->byName($request);
     };
     $options = array('callback' => $cb, 'timeout' => $this->ttl, 'cache_missing' => TRUE, 'method' => 'add');
     $cacher = new Store\Callback($this->cacher('name'), $options);
     return $cacher->get($request);
 }
 /**
  * @see StockPile_Interface::fetch()
  * works the same way, but gets its values from the cache when it can.
  * if no ids were passed in, that means they want the complete list.
  *  hopefully most of the time the calling app will specify which ids they are looking for.
  * much more efficient that way.
  * if no ids passed in and we get a cache miss, we gotta get all the keys again.
  *  might as well get the data too. when repopulating the row-wise cache, be careful not to
  * clobber data that was populated by add or subtract calls. only populate if missing.
  * use cache add approach ... much cleaner ... avoids race condition where
  * db updates at the same time some other process loads and accidentally
  * clobbers the value from the write.
  * if the refresh flag was set for this object, go ahead and overwrite anything in the cache.
  * this should only be used when debugging. not useful on production, and a little dangerous.
  * this method uses cache callback to do row-wise caching.
  * it uses the ids supplied as the keys, or if none supplied, the index that also lives in the cache.
  */
 public function fetch(array $ids = NULL)
 {
     $cache = $this->cacher;
     $timeout = $this->cacheTimeout();
     if ($ids === NULL) {
         $ids = !$this->refresh ? $cache->get(self::INDEX_CACHEKEY) : NULL;
         if (!is_array($ids)) {
             $rows = $this->core->fetch();
             $method = !$this->refresh ? 'add' : 'set';
             $cache->{$method}(self::INDEX_CACHEKEY, array_keys($rows), $timeout);
             foreach ($rows as $k => $v) {
                 $cache->{$method}($k, $v, 0, $timeout);
             }
             return $rows;
         }
     }
     if (count($ids) < 1) {
         return array();
     }
     if ($this->refresh) {
         $rows = $this->core->fetch($ids);
         foreach ($rows as $k => $v) {
             $cache->set($k, $v, $timeout);
         }
         return $rows;
     }
     $options = array('callback' => array($this->core, 'fetch'), 'method' => 'add', 'timeout' => $timeout, 'cache_missing' => TRUE);
     $cb = new Store\Callback($cache, $options);
     $result = $cb->get($ids);
     if (!is_array($result)) {
         $result = array();
     }
     foreach ($result as $item => $quantity) {
         $result[$item] = $this->defaultQuantity($quantity);
     }
     return $result;
 }
 /**
  * @see Stockpile_Interface::fetch();
  */
 public function fetch(array $item_ids = NULL)
 {
     $res = $this->core->fetch($item_ids);
     $ids = array_keys($res);
     if (count($ids) <= 1) {
         return $res;
     }
     if ($this->cacher) {
         $timeout = $this->cachetimeout();
         $options = array('callback' => array($this, 'fetchPos'), 'method' => 'add', 'timeout' => $timeout, 'cache_missing' => TRUE);
         $cacher = new Store\Callback($this->cacher, $options);
         $result = $cacher->get($ids);
     } else {
         $result = $this->fetchPos($ids);
     }
     if (!is_array($result)) {
         $result = array();
     }
     $sorter = new CompareSort($result);
     uksort($res, array($sorter, 'compare'));
     return $res;
 }