A trap used by the PHP cache
Look at the code first:
/** * Get settings information */public function getcoinsetting () {$cache = Common::gettair (); $ckey = Common::hashkey ("Hello"); $ret = $cache ->get ($ckey), if ($ret) return Json_decode ($ret, true); $taomanyiApiService = $this->_gettmiapiservice (); $result = $taomanyiApiService->getcoinsetting (); $cache->set ($ckey, Json_encode ($result), 3600); return $result;}
This is an instance of using the Tair memory cache, in which the cache is set and the cache time is 3,600 seconds. The data is obtained from the API, what if the writing is problematic? If:
$result = $taomanyiApiService->getcoinsetting ();
$result get the data is empty, because the $result data is from the HTTP request, the data is not normal is more common things. In this situation, the HTTP request fails, then the interface data is not requested, and the next process is to set the cache
$cache->set ($ckey, Json_encode ($result), 3600);
We will find that because of the failure of an interface HTTP request, we accidentally cache the empty data for 3,600 seconds. This will appear on the page, such as the classification of data gaps, affecting the entire business process
We do the following optimizations: