bag = array(); } /** * @param $key string * @return bool */ protected function expire( $key ) { $et = $this->bag[$key][1]; if ( ( $et == 0 ) || ( $et > time() ) ) { return false; } $this->delete( $key ); return true; } /** * @param $key string * @return bool|mixed */ function get( $key ) { if ( !isset( $this->bag[$key] ) ) { return false; } if ( $this->expire( $key ) ) { return false; } return $this->bag[$key][0]; } /** * @param $key string * @param $value mixed * @param $exptime int * @return bool */ function set( $key, $value, $exptime = 0 ) { $this->bag[$key] = array( $value, $this->convertExpiry( $exptime ) ); return true; } /** * @param $key string * @param $time int * @return bool */ function delete( $key, $time = 0 ) { if ( !isset( $this->bag[$key] ) ) { return false; } unset( $this->bag[$key] ); return true; } /** * @return array */ function keys() { return array_keys( $this->bag ); } }