$value){ if(!empty($value) and !array_key_exists('errors', $value)){ $expired = time() + ( $storage_time * 60 ); $cache[$host_id][$key] = ['data' => $value, 'expired' => $expired]; $result[$key] = true; } else { $result[$key] = false; } } WebTotemOption::setOptions(['cache' => $cache]); return $result; } /** * Get data from cache. * * @param string $key * Data key. * @param string $host_id * The data belongs to this host. * * @return array * Returns saved data by key. */ public static function getdata($key, $host_id) { $cache = json_decode(WebTotemOption::getOption('cache'), true) ?: []; if(array_key_exists($host_id, $cache) and array_key_exists($key, $cache[$host_id]) ) { // and $cache[$host_id][$key]['expired'] > time() return [ 'data' => $cache[$host_id][$key]['data'], 'remained' => $cache[$host_id][$key]['expired'] - time(), ]; } else { return []; } } /** * Delete data from cache. * * @param string $key * Data key. * @param string $host_id * The data belongs to this host. * * @return bool */ public static function deleteData($key, $host_id) { $cache = json_decode(WebTotemOption::getOption('cache'), true) ?: []; unset($cache[$host_id][$key]); WebTotemOption::setOptions(['cache' => $cache]); return TRUE; } }