コード例 #1
0
ファイル: test_cacheTest.php プロジェクト: jinshana/kajonacms
 public function testCacheing()
 {
     $objCache = class_cache::createNewInstance(self::$strCacheSource);
     $objCache->setStrHash1("testCache");
     $objCache->setStrContent("testContent");
     $objCache->setIntLeasetime(time() + 100);
     $objCache->updateObjectToDb();
     $this->flushDBCache();
     class_cache::cleanCache();
     $objEntries = class_cache::getCachedEntry(self::$strCacheSource, "testCache");
     $this->assertNotNull($objEntries);
     $this->assertEquals("testContent", $objEntries->getStrContent());
 }
コード例 #2
0
ファイル: class_cache.php プロジェクト: jinshana/kajonacms
 /**
  * Saves the object to the database.
  * Differs between update or insert.
  *
  * @throws class_exception
  * @return bool
  */
 public function updateObjectToDb()
 {
     //run a cleanup
     class_cache::cleanCache();
     //at least a source and hash1 given?
     if ($this->strSourceName == "" && $this->strHash1 == "") {
         throw new class_exception("not all required params given", class_exception::$level_ERROR);
     }
     //check if the new entry will be valid at least a second, otherwise quit saving
     if (time() > $this->intLeasetime) {
         return false;
     }
     $strQuery = "";
     $arrParams = array();
     $arrEscape = array();
     if ($this->strCacheId == null) {
         $this->strCacheId = generateSystemid();
         //insert
         $strQuery = "INSERT INTO " . _dbprefix_ . "cache\n                       (cache_id, cache_source, cache_hash1, cache_hash2, cache_language, cache_content, cache_leasetime, cache_hits) VALUES\n                       (   ?, ?, ?, ?, ?, ?, ?, 1) ";
         $arrParams = array($this->strCacheId, $this->getStrSourceName(), $this->getStrHash1(), $this->getStrHash2(), $this->getStrLanguage(), $this->getStrContent(), $this->getIntLeasetime());
         $arrEscape = array(true, true, true, true, true, false, true);
     } else {
         //update
         $strQuery = "UPDATE " . _dbprefix_ . "cache\n                            SET cache_source = ?,\n                                cache_hash1 = ?,\n                                cache_hash2 = ?,\n                                cache_language = ?,\n                                cache_content = ?,\n                                cache_leasetime = ?\n                          WHERE cache_id = ?";
         $arrParams = array($this->getStrSourceName(), $this->getStrHash1(), $this->getStrHash2(), $this->getStrLanguage(), $this->getStrContent(), $this->getIntLeasetime(), $this->strCacheId);
         $arrEscape = array(true, true, true, true, false, true, true);
     }
     self::$intSaves++;
     return $this->objDB->_pQuery($strQuery, $arrParams, $arrEscape);
 }