public function flushPersistentCaches() { PersistentCache::flush(); Session::flash('success', 'Les caches persistentes ont été effacés avec succès.'); return redirect('admin'); }
private static function getBGGUrl($url, $mode = 'url', $parameter = [], $numTry = 0) { $keyCache = 'url_' . md5($url) . '_' . $GLOBALS['parameters']['typeLogin']; // Si on est pas connecté, mais qu'il existe une cache pour l'utilisateur connecté, on obtient cette dernière if ($GLOBALS['parameters']['typeLogin'] == 'guest') { $tempKeyCache = 'url_' . md5($url) . '_login'; if (Cache::has($tempKeyCache) || PersistentCache::has($tempKeyCache)) { $keyCache = $tempKeyCache; } } if (Cache::has($keyCache)) { $contentUrl = Cache::get($keyCache); } elseif (PersistentCache::has($keyCache) && !isset($_GET['force'])) { $contentUrl = PersistentCache::get($keyCache); } else { try { Log::info('Get info from bgg : ' . $url); if ($mode == 'curl') { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIE, $parameter['cookie']); curl_setopt($ch, CURLOPT_URL, $url); $contentUrl = curl_exec($ch); } else { $contentUrl = file_get_contents($url); } } catch (\Exception $e) { Log::error($e); Session::flash('error', 'Réessayez un peu plus tard.'); return redirect('home'); } Cache::put($keyCache, $contentUrl, self::CACHE_TIME_IN_MINUTES); PersistentCache::put($keyCache, $contentUrl); } @($simpleXmlObject = simplexml_load_string($contentUrl)); if (!$simpleXmlObject) { Cache::forget($keyCache); } $arrayData = json_decode(json_encode($simpleXmlObject), true); // Retry if data is not valid if (self::dataInvalid($arrayData)) { if ($numTry < self::LOAD_NUMBER_TRY) { Cache::forget($keyCache); sleep($numTry * self::LOAD_WAIT_BETWEEN_TRY); $arrayData = self::getBGGUrl($url, $mode, $parameter, ++$numTry); } else { throw new \Exception('Can\'t get url ' . $url . ' after ' . $numTry . ' try.'); } } return $arrayData; }