/** * Main function for getting MarketPrices objects. Tries caches and instantiates new objects if necessary. * * @param int $typeId of type * @param int $regionId of the region. If none passed, default is looked up. * @param int $maxPriceDataAge for the maximum acceptable market data age. Use null for unlimited. * * @return \iveeCore\MarketPrices * @throws \iveeCore\Exceptions\NotOnMarketException if requested type is not on market * @throws \iveeCore\Exceptions\NoPriceDataAvailableException if no region market data is found */ public static function getByIdAndRegion($typeId, $regionId = null, $maxPriceDataAge = null) { //setup instance pool if needed if (!isset(static::$instancePool)) { static::init(); } //get default market regionId if none passed if (is_null($regionId)) { $regionId = Config::getDefaultMarketRegionId(); } //try instance pool and cache try { $mp = static::$instancePool->getItem(static::getClassHierarchyKeyPrefix() . (int) $regionId . '_' . (int) $typeId); if (!$mp->isTooOld($maxPriceDataAge)) { return $mp; } } catch (KeyNotFoundInCacheException $e) { //empty as we are using Exceptions for flow control here } $mpClass = Config::getIveeClassName(static::getClassNick()); //try DB try { $mp = new $mpClass($typeId, $regionId, $maxPriceDataAge); //use it only if its not too old or unlimited if (!$mp->isTooOld($maxPriceDataAge)) { static::$instancePool->setItem($mp); return $mp; } } catch (NoPriceDataAvailableException $e) { //empty as we are using Exceptions for flow control here } if (is_null(static::$crestMarketProcessor)) { $crestMarketProcessorClass = Config::getIveeClassName('CrestMarketProcessor'); static::$crestMarketProcessor = new $crestMarketProcessorClass(); } //fetch data from CREST and update DB //we don't cache the CREST call because we already cache this object $data = static::$crestMarketProcessor->getNewestPriceData($typeId, $regionId, false); //instantiate new MarketPrice $mp = new $mpClass($typeId, $regionId, $maxPriceDataAge, $data); //store object in instance pool and cache static::$instancePool->setItem($mp); return $mp; }