示例#1
0
 /**
  * @param     $itemID
  * @param int $retry
  * @return APIItemV2
  */
 public static function getItemById($itemID, $retry = 3)
 {
     $cache = CacheHandler::getInstance('item_gw2api');
     $cacheKey = $itemID . "::" . substr(md5($itemID), 0, 10);
     $ttl = 86400;
     if (!($API_JSON = $cache->get($cacheKey))) {
         for ($i = 0; $i < $retry; $i++) {
             try {
                 $curl_item = CurlRequest::newInstance(getAppConfig('gw2spidy.gw2api_url') . "/v1/item_details.json?item_id={$itemID}")->exec();
                 $API_JSON = $curl_item->getResponseBody();
                 $cache->set($cacheKey, $API_JSON, MEMCACHE_COMPRESSED, $ttl);
                 return self::getSingleItemByJSON($API_JSON);
             } catch (\Exception $e) {
                 // - supress and short sleep
                 usleep(0.2 * 1000 * 1000);
                 // 0.2s
             }
         }
         $ttl = 60;
         $cache->set($cacheKey, null, MEMCACHE_COMPRESSED, $ttl);
         return null;
     } else {
         return self::getSingleItemByJSON($API_JSON);
     }
 }
示例#2
0
 protected static function getGemCache()
 {
     if (is_null(self::$cache)) {
         self::$cache = CacheHandler::getInstance('gem_chart');
     }
     return self::$cache;
 }
示例#3
0
 public static function getRecipeById($dataId)
 {
     $cache = CacheHandler::getInstance('recipe_gw2api');
     $cacheKey = $dataId . "::" . substr(md5($dataId), 0, 10);
     $ttl = 86400;
     if (!($API_JSON = $cache->get($cacheKey))) {
         try {
             $curl_item = CurlRequest::newInstance(getAppConfig('gw2spidy.gw2api_url') . "/v1/recipe_details.json?recipe_id={$dataId}")->exec();
             $API_JSON = $curl_item->getResponseBody();
             $cache->set($cacheKey, $API_JSON, MEMCACHE_COMPRESSED, $ttl);
         } catch (\Exception $e) {
             $ttl = 600;
             $cache->set($cacheKey, null, MEMCACHE_COMPRESSED, $ttl);
             return null;
         }
     }
     return APIRecipe::getRecipeByJSON($API_JSON);
 }
示例#4
0
<?php

use GW2Spidy\Dataset\DatasetManager;
use GW2Spidy\Util\CacheHandler;
require dirname(__FILE__) . '/../autoload.php';
// memcache is completely purged this way
if (array_intersect(array('-m', '--all'), $argv)) {
    CacheHandler::getInstance("purge")->purge();
    echo "cleared memcache \n";
}
if (array_intersect(array('-d', '--all'), $argv)) {
    DatasetManager::getInstance()->purgeCache();
    echo "cleared dataset \n";
}
if (array_intersect(array('-a', '--all'), $argv) && function_exists('apc_clear_cache') && ($host = getAppConfig("apc_clear_cache_host"))) {
    apc_clear_cache();
    apc_clear_cache('user');
    apc_clear_cache('opcode');
    $hash = md5(uniqid());
    $targetDir = dirname(dirname(__FILE__)) . "/webroot/tmp";
    $target = "{$targetDir}/{$hash}.php";
    if (!is_dir($targetDir)) {
        mkdir($targetDir);
    }
    copy(dirname(__FILE__) . "/clear_apc_cache.php", $target);
    $url = "http://{$host}/tmp/{$hash}.php";
    $result = json_decode(file_get_contents($url), true);
    if (isset($result['success']) && $result['success']) {
        echo "cleared apc \n";
    } else {
        echo "failed to clear apc \n";