Пример #1
0
function lib_json(&$ctag, &$refObj)
{
    global $dsql, $sqlCt, $cfg_soft_lang;
    $attlist = "url|";
    FillAttsDefault($ctag->CAttribute->Items, $attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    $Innertext = trim($ctag->GetInnerText());
    if ($url == '' || $Innertext == '') {
        return '';
    }
    $ctp = new DedeTagParse();
    $ctp->SetNameSpace('field', '[', ']');
    $ctp->LoadSource($Innertext);
    $mcache = new MiniCache();
    $GLOBALS['autoindex'] = 0;
    $chash = md5($url);
    if (!($row = $mcache->Get($chash))) {
        $content = @file_get_contents($url);
        $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        $row = $json->decode($content);
        if ($cfg_soft_lang != 'utf-8') {
            $row = AutoCharset($row, 'utf-8', 'gb2312');
        }
        $mcache->Save($chash, $row, $cache);
    }
    $revalue = "";
    foreach ($row as $key => $value) {
        $GLOBALS['autoindex']++;
        foreach ($ctp->CTags as $tagid => $ctag) {
            if ($ctag->GetName() == 'array') {
                $ctp->Assign($tagid, $value);
            } else {
                if (!empty($value[$ctag->GetName()])) {
                    $ctp->Assign($tagid, $value[$ctag->GetName()]);
                } else {
                    $ctp->Assign($tagid, "");
                }
            }
        }
        $revalue .= $ctp->GetResult();
    }
    return $revalue;
}
Пример #2
0
 /**
  *  私有化构造函数,防止外界实例化对象
  */
 private function __construct()
 {
     parent::MiniCache();
 }
Пример #3
0
 /**
  * ------------------------------------------------------
  * Destroy the instance
  * ------------------------------------------------------
  */
 public function destroyInstance()
 {
     self::$_instance->_loaded = array();
     self::$_instance = NULL;
 }
Пример #4
0
 public function testExpiration()
 {
     $durations = array(-1, 0, 1);
     foreach ($durations as $duration) {
         $cacheKey = 'exp' . $duration;
         $mc = MiniCache::getInstance();
         $mc->set($cacheKey, 'my test string', $duration);
         $beforeExpiration = $mc->get($cacheKey);
         if ($duration >= 0) {
             sleep($duration + 1);
         }
         $mc->deleteExpired();
         $afterExpiration = $mc->get($cacheKey);
         if ($duration >= 0) {
             $this->assertEquals($afterExpiration, FALSE);
         } else {
             $this->assertEquals($afterExpiration, $beforeExpiration);
         }
     }
     $mc = MiniCache::getInstance();
     $mc->delete('exp-1');
 }