You are here

function pCache::isInCache in Visitors 7

Same name and namespace in other branches
  1. 8 pchart/pCache.inc \pCache::IsInCache()
  2. 7.2 pChart/class/pCache.class.php \pCache::isInCache()
  3. 7.0 pchart/pCache.inc \pCache::IsInCache()
2 calls to pCache::isInCache()
pCache::dbRemoval in pChart/class/pCache.class.php
pCache::getFromCache in pChart/class/pCache.class.php

File

pChart/class/pCache.class.php, line 167

Class

pCache

Code

function isInCache($ID, $Verbose = FALSE, $UpdateHitsCount = FALSE) {

  /* Compute the paths */
  $Index = $this->CacheFolder . "/" . $this->CacheIndex;

  /* Search the picture in the index file */
  $Handle = @fopen($Index, "r");
  while (!feof($Handle)) {
    $IndexPos = ftell($Handle);
    $Entry = fgets($Handle, 4096);
    if ($Entry != "") {
      $Settings = preg_split("/,/", $Entry);
      $PicID = $Settings[0];
      if ($PicID == $ID) {
        fclose($Handle);
        $DBPos = $Settings[1];
        $PicSize = $Settings[2];
        $GeneratedTS = $Settings[3];
        $Hits = intval($Settings[4]);
        if ($UpdateHitsCount) {
          $Hits++;
          if (strlen($Hits) < 7) {
            $Hits = $Hits . str_repeat(" ", 7 - strlen($Hits));
          }
          $Handle = @fopen($Index, "r+");
          fseek($Handle, $IndexPos);
          fwrite($Handle, $PicID . "," . $DBPos . "," . $PicSize . "," . $GeneratedTS . "," . $Hits . "\r\n");
          fclose($Handle);
        }
        if ($Verbose) {
          return array(
            "DBPos" => $DBPos,
            "PicSize" => $PicSize,
            "GeneratedTS" => $GeneratedTS,
            "Hits" => $Hits,
          );
        }
        else {
          return TRUE;
        }
      }
    }
  }
  fclose($Handle);

  /* Picture isn't in the cache */
  return FALSE;
}