public function saveStatus($serviceName, $attributeName, $value, $flush = false) {
        // before writing we load the data no matter what
        $this->loadStatsArray();

        // if this service is unknown add it to dirty array
        $this->dirtyStats[$serviceName][$attributeName] = $value;
        $this->stats[$serviceName][$attributeName] = $value;

        if ($flush) {
            // force reload stats
            $this->stats = false;
            $this->loadStatsArray();

            // merge all dirty stats into the oryginal array
            foreach ($this->dirtyStats as $service => $values) {
                foreach ($values as $name => $value) {
                    $this->stats[$service][$name] = $value;
                }
            }

            // force save
            $this->saveStatsArray();

            // next time we wont override these any more (they could change in the mean time)
            $this->dirtyStats = array();
        }
    }
public function saveStatus($serviceName, $attributeName, $value, $flush = false) {
        // before writing we load the data no matter what
        $this->loadStatsArray();

        // if this service is unknown add it to dirty array
        $this->dirtyStats[$serviceName][$attributeName] = $value;
        $this->stats[$serviceName][$attributeName] = $value;

        if ($flush) {
            // force reload stats
            $this->stats = false;
            $this->loadStatsArray();

            // merge all dirty stats into the oryginal array
            foreach ($this->dirtyStats as $service => $values) {
                foreach ($values as $name => $value) {
                    $this->stats[$service][$name] = $value;
                }
            }

            // force save
            $this->saveStatsArray();

            // next time we wont override these any more (they could change in the mean time)
            $this->dirtyStats = array();
        }
    }
public function saveStatus ( $ serviceName , $ attributeName , $ value , $ flush = false ) { // before writing we load the data no matter what
 $ this -> loadStatsArray ( ) ; // if this service is unknown add it to dirty array
 $ this -> dirtyStats [ $ serviceName ] [ $ attributeName ] = $ value ; $ this -> stats [ $ serviceName ] [ $ attributeName ] = $ value ; if ( $ flush ) { // force reload stats
 $ this -> stats = false ; $ this -> loadStatsArray ( ) ; // merge all dirty stats into the oryginal array
 foreach ( $ this -> dirtyStats as $ service => $ values ) { foreach ( $ values as $ name => $ value ) { $ this -> stats [ $ service ] [ $ name ] = $ value ; } } // force save
 $ this -> saveStatsArray ( ) ; // next time we wont override these any more (they could change in the mean time)
 $ this -> dirtyStats = array ( ) ; } }
We reload values just before saving to reduce race condition time.
The updated values are merged with previous values.
Then everything is stored back into the storage

@param 	string  $serviceName   name of service to load stats for
@param 	string  $attributeName name of the attribute to load
@param 	string  $value         string value loaded or '' if nothing found
@param   boolean $flush         set to true will force immediate save, false does not guaranteed saving at all.
@return 	void

@throws Ejsmont\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used
We reload values just before saving to reduce race condition time . The updated values are merged with previous values . Then everything is stored back into the storage