$value){ $expired = time() + ( $storage_time * 60 ); $cache[$host_id][$key] = ['data' => $value, 'expired' => $expired]; } WebTotemOption::setOptions(['cache' => $cache]); return TRUE; } /** * 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 []; } } }