public function actionCacheProducts() { $chemicals = those('chemical')->orderBy('cas_no', 'asc'); $cacher = \Gini\Cache::of('chemdb'); $timeout = 86400 * 30; foreach ($chemicals as $c) { $key = "chemical[{$c->cas_no}]"; $data = ['cas_no' => $c->cas_no, 'name' => $c->name, 'types' => $c->types(), 'state' => $c->state, 'en_name' => $c->en_name, 'aliases' => $c->aliases, 'en_aliases' => $c->en_aliases, 'einecs' => $c->einecs, 'mol_formula' => $c->mol_formula, 'mol_weight' => $c->mol_weight, 'inchi' => $c->inchi, 'melting_point' => $c->melting_point, 'boiling_point' => $c->boiling_point, 'flash_point' => $c->flash_point]; $cacher->set($key, $data, $timeout); } }
private static function _getInventoryVolume($cas_no, $group_id) { if (!$group_id) { return ['error' => '组信息丢失']; } $cache = \Gini\Cache::of('cas-volume'); $key = "cas-volume-inv[{$cas_no}][{$group_id}]"; $volume = $cache->get($key); if (false === $volume) { $rpc = self::getRPC('lab-inventory'); $volume = $rpc->mall->inventory->getHazardousTotal($cas_no, $group_id); $cache->set($key, $volume, 15); } return ['volume' => $volume]; }