Jump to content

comparing cached file time fails


Agony
 Share

Recommended Posts

failure is here:

    public function check_cache(){        if(file_exists($this->file)){            if((time() - $this->time) < filemtime($this->file)){                return include($this->file);            }        }        else{          return false;        }    } 

It works fine most of the time - but around once a day, the whole statement fails and ends up as null.

 

Which means it wont include the cached file and wont start the code to cache new one.

it seems to fail at timecheck - even tho manually echoing each side i compare - it should be ether true or false but it seems to do fail - so its nether true or false and there for even the else part wont run.Will it automatically round the timestamps somehow at one point so they are equal?

Edited by Agony
Link to comment
Share on other sites

    private $file;    private $time;    public function __construct($filename,$cachefolder,$cachetime){        $this->file = $cachefolder.$filename;        $this->time = $cachetime;    }

thats all - values are passed to the class through the constructor.

$gallery_cache = new cache($gallerycachename,$cachefolder,$cachetime);

$cashetime is from the database a and its stored in seconds. in Varchar field.The value is accessed:

$cachetime = intval ($config['data']['assoc']['cachetime']);
Link to comment
Share on other sites

Well, I cant inteprete much in your code, its complicating but since you said neither if nor else works then your error should be from this algorithm

if(file_exists($this->file)){            if((time() - $this->time) < filemtime($this->file)){                return include($this->file);            }

which if file exist works then nested if. What if the expression returns false??? What if it is not less than???

Edited by Don Jajo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...