|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
pauloricardo Smarty Rookie
Joined: 19 Oct 2009 Posts: 5
|
Posted: Mon Oct 19, 2009 7:25 pm Post subject: Caching problem |
|
|
Hi,
After all, everything is Ok with my script.
But I need to improve it. I'm caching some data of Twitter API, with a cache_lifetime of 3600 seconds (1 hour). Occasionally, the connection with Twitter timed out and I end up writing to cache incomplete information.
What I need: a way to ignoring caching when assigned data is not as expected. But I don't know what logic I need to use.
Thanks in advance,
pauloricardo |
|
Back to top |
|
pauloricardo Smarty Rookie
Joined: 19 Oct 2009 Posts: 5
|
Posted: Tue Oct 20, 2009 11:55 pm Post subject: |
|
|
I workarounded this problem in a not very elegant way :
Code: | public function fetch() // it's the method that I use to get cache contents within my own class
{
// If locked, clear cache
if ($this->_isLocked()) {
$this->clearCache(); // this calls Smarty clear_cache() method and delete .lock file related
}
// No cache available
if (!$this->_smarty->is_cached($this->_template_file)) {
$data = $this->_getData(); // here I get Twitter API data
$this->_smarty->assign('widget_data', $data);
// Lock
if (!$data) {
$this->_createLockFile();
}
}
return $this->_smarty->fetch($this->_template_file);
} |
Does anyone have any better suggestions?
Thanks in advance,
pauloricardo |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|