cache.php File Reference

Go to the source code of this file.

Functions


Function Documentation

get_db_cache ( sql,
&$  var,
filename,
refresh = false 
)

Get data from the cache or the database.

Definition at line 85 of file cache.php.

00085                                                                  {
00086     $DB=Database::getInstance();
00087     $var = array();
00088 
00089 // check for the refresh flag and try to the data
00090     if (($refresh == true)|| !read_cache($var, $filename)) {
00091 // Didn' get cache so go to the database.
00092 //      $conn = mysql_connect("localhost", "apachecon", "apachecon");
00093       $res = $DB->query($sql);
00094 //      if ($err = mysql_error()) trigger_error($err, E_USER_ERROR);
00095 // loop through the results and add them to an array
00096       while ($rec = $res->fetchAssoc()) {
00097         $var[] = $rec;
00098       }
00099 // write the data to the file
00100       write_cache($var, $filename);
00101     }
00102   }

read_cache ( &$  var,
filename,
auto_expire = false 
)

Read in seralized data.

Definition at line 49 of file cache.php.

Referenced by get_db_cache(), tep_cache_also_purchased(), tep_cache_categories_box(), and tep_cache_manufacturers_box().

00049                                                              {
00050     $filename = DIR_FS_CACHE . $filename;
00051     $success = false;
00052 
00053     if (($auto_expire == true) && file_exists($filename)) {
00054       $now = time();
00055       $filetime = filemtime($filename);
00056       $difference = $now - $filetime;
00057 
00058       if ($difference >= $auto_expire) {
00059         return false;
00060       }
00061     }
00062 
00063 // try to open file
00064     if ($fp = @fopen($filename, 'r')) {
00065 // read in serialized data
00066       $szdata = fread($fp, filesize($filename));
00067       fclose($fp);
00068 // unserialze the data
00069       $var = unserialize($szdata);
00070 
00071       $success = true;
00072     }
00073 
00074     return $success;
00075   }

tep_cache_also_purchased ( auto_expire = false,
refresh = false 
)

Cache the also purchased module.

Definition at line 146 of file cache.php.

00146                                                                             {
00147     global $_GET, $language, $languages_id;
00148 
00149     if (($refresh == true) || !read_cache($cache_output, 'also_purchased-' . $language . '.cache' . $_GET['products_id'], $auto_expire)) {
00150       ob_start();
00151       include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
00152       $cache_output = ob_get_contents();
00153       ob_end_clean();
00154       write_cache($cache_output, 'also_purchased-' . $language . '.cache' . $_GET['products_id']);
00155     }
00156 
00157     return $cache_output;
00158   }

tep_cache_categories_box ( auto_expire = false,
refresh = false 
)

Cache the categories box.

Definition at line 107 of file cache.php.

00107                                                                             {
00108     global $cPath, $language, $languages_id, $tree, $cPath_array, $categories_string;
00109 
00110     if (($refresh == true) || !read_cache($cache_output, 'categories_box-' . $language . '.cache' . $cPath, $auto_expire)) {
00111       ob_start();
00112       include(DIR_WS_BOXES . 'categories.php');
00113       $cache_output = ob_get_contents();
00114       ob_end_clean();
00115       write_cache($cache_output, 'categories_box-' . $language . '.cache' . $cPath);
00116     }
00117 
00118     return $cache_output;
00119   }

tep_cache_manufacturers_box ( auto_expire = false,
refresh = false 
)

Cache the manufacturers box.

Definition at line 124 of file cache.php.

00124                                                                                {
00125     global $_GET, $language;
00126 
00127     $manufacturers_id = '';
00128     if (isset($_GET['manufactuers_id']) && tep_not_null($_GET['manufacturers_id'])) {
00129       $manufacturers_id = $_GET['manufacturers_id'];
00130     }
00131 
00132     if (($refresh == true) || !read_cache($cache_output, 'manufacturers_box-' . $language . '.cache' . $manufacturers_id, $auto_expire)) {
00133       ob_start();
00134       include(DIR_WS_BOXES . 'manufacturers.php');
00135       $cache_output = ob_get_contents();
00136       ob_end_clean();
00137       write_cache($cache_output, 'manufacturers_box-' . $language . '.cache' . $manufacturers_id);
00138     }
00139 
00140     return $cache_output;
00141   }

write_cache ( &$  var,
filename 
)

Write out serialized data.

Definition at line 24 of file cache.php.

Referenced by get_db_cache(), tep_cache_also_purchased(), tep_cache_categories_box(), and tep_cache_manufacturers_box().

00024                                          {
00025     $filename = DIR_FS_CACHE . $filename;
00026     $success = false;
00027 
00028 // try to open the file
00029     if ($fp = @fopen($filename, 'w')) {
00030 // obtain a file lock to stop corruptions occuring
00031       flock($fp, 2); // LOCK_EX
00032 // write serialized data
00033       fputs($fp, serialize($var));
00034 // release the file lock
00035       flock($fp, 3); // LOCK_UN
00036       fclose($fp);
00037       $success = true;
00038     }
00039 
00040     return $success;
00041   }