More fixes applied from profi-conecpt, cache system rewritten: now all cache files...
[mailer.git] / inc / libs / cache_functions.php
index a3b1d0a15e77831db0bf6c1d430869a2d2f426d6..88b506223d9f6fdd1ecf162e97de9a05ddf664ad 100644 (file)
@@ -49,6 +49,7 @@ class mxchange_cache
        var $cache_pointer = false;
        var $cache_data = "";
        var $cache_version = "";
+       var $cache_file = "";
 
        // Constructor
        function mxchange_cache($interval, $path, $tested) {
@@ -87,8 +88,11 @@ class mxchange_cache
                }
        }
 
-       function cache_file($file, $ignore_ctime=false) {
-               global $INC;
+       // Checks validity of cache file and if content is given
+       function cache_file ($file, $forceContent = false) {
+               // Remember cache file
+               $this->cache_file = $file;
+
                // Construct FQFN (full qualified file name)
                $inc = $this->cache_path.$file.".cache";
 
@@ -109,10 +113,10 @@ class mxchange_cache
                $this->cache_ctime = $ctime;
 
                // Is the cache file outdated?
-               if (((time() - $ctime) >= $this->update_interval) && (!$ignore_ctime)) {
+               if (($status) && ((time() - $ctime) >= $this->update_interval)) {
                        // Ok, we need an update!
                        $status = false;
-               }
+               } // END - if
 
                // Return status
                return $status;
@@ -196,23 +200,29 @@ class mxchange_cache
                        $cache_version = null;
 
                        // Load cache file
-                       $this->cache_data = implode("", file($this->cache_inc));
+                       $this->cache_data[$this->cache_file] = implode("", file($this->cache_inc));
 
                        // Execute cache file
-                       eval($this->cache_data);
+                       eval($this->cache_data[$this->cache_file]);
 
                        if (is_array($data)) {
                                // Cache data
-                               $this->cache_data = $data;
+                               $this->cache_data[$this->cache_file] = $data;
 
                                // Cache version found?
-                               if ((isset($cache_version)) && (is_array($cache_version))) {
+                               if ((is_array($cache_version)) && (count($cache_version) > 0)) {
                                        // Remember it as well...
-                                       $this->cache_version = $cache_version;
-                               } // END - if
+                                       $this->cache_version[$this->cache_file] = $cache_version;
+                               } else {
+                                       // Invalid cache so destroy it
+                                       $this->cache_destroy();
+
+                                       // Clear cached data
+                                       $this->cache_data[$this->cache_file] = array();
+                               }
 
                                // Return cache
-                               return $this->cache_data;
+                               return $this->cache_data[$this->cache_file];
                        } else {
                                // Cache problem detected!
                                $this->cache_destroy();
@@ -242,8 +252,7 @@ class mxchange_cache
                }
        }
 
-       function cache_remove($search, $data, $array)
-       {
+       function cache_remove($search, $data, $array) {
                global $ARRAY;
                if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc))) {
                        // Load cache into dummy array
@@ -287,8 +296,7 @@ class mxchange_cache
                }
        }
 
-       function cache_replace($search, $replace, $search_key, $array)
-       {
+       function cache_replace($search, $replace, $search_key, $array) {
                global $ARRAY;
                if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc)))
                {
@@ -361,9 +369,8 @@ class mxchange_cache
                // Get extension version
                $ext_ver = GET_EXT_VERSION($ext_name);
 
-               //* DEBUG: */ echo __METHOD__.": ext_name={$ext_name},ext_ver={$ext_ver},cache_version={$this->cache_version}<br />\n";
                // Compare both
-               return ((isset($this->cache_version[$ext_name])) && ($this->cache_version[$ext_name] == $ext_ver));
+               return ((isset($this->cache_version[$this->cache_file][$ext_name])) && ($this->cache_version[$this->cache_file][$ext_name] == $ext_ver));
        }
 
        function add_raw_row ($key, $value) {