hendeca
Forum Replies Created
-
Forum: Plugins
In reply to: [EP Hashimage] New content only visible after cache clearHey guys,
I have a fix for this issue, or at least I’ve located the problem. The problem lies in this block of code on line starting on line 184 of hashimage.php:
/** * Fetch the url **/ private function _fetchurl($url = null, $ttl = 86400){ if ($url) { $option_name = 'hashimage_cache_'.md5($url); // Chec if cache of the urls allready exists, if not, get content of the url if (false === ($data = get_site_transient($option_name))) { $ch = curl_init(); $options = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 10 ); curl_setopt_array($ch, $options); $data['chunk'] = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http_code === 200){ // Set the new cache set_site_transient($option_name, $data, $ttl); } } return $data['chunk']; } }
Change this to:
/** * Fetch the url **/ private function _fetchurl($url = null, $ttl = 86400){ if ($url) { $ch = curl_init(); $options = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 10 ); curl_setopt_array($ch, $options); $data['chunk'] = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http_code === 200){ // Set the new cache set_site_transient($option_name, $data, $ttl); } return $data['chunk']; } }
Looks like if (false === ($data = get_site_transient($option_name))) { is evaluating to false every time unless the cache is cleared. If I’m not mistaken, this is checking for the transient “hashimage_cache_” but the logic doesn’t seem to make sense. Essentially if it is set then no new content is loaded. However it looks like there’s no reason why that transient wouldn’t be set unless the cache has just been cleared. I may not be fully understanding the code, but from what I can tell, this will only ever evaluate to true if the cache has just been cleared.
Secondly, the 15 minute refresh is actually set to 150 minutes. The correct value should be 90,000 ms for the setInterval in async.js on line 18. Here’s the code with the corrected value:
setInterval(function(){ getImages(this, link_path, dataurl); }, 90000); // 90,000
Hope this helps someone! Worked for me after these changes! Thanks for this plugin, I really enjoy it!