Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Caching problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pauloricardo
Smarty Rookie


Joined: 19 Oct 2009
Posts: 5

PostPosted: Mon Oct 19, 2009 7:25 pm    Post subject: Caching problem Reply with quote

Hi,

After all, everything is Ok with my script. Smile

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. Sad

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. Mad

Thanks in advance,
pauloricardo
Back to top
View user's profile Send private message
pauloricardo
Smarty Rookie


Joined: 19 Oct 2009
Posts: 5

PostPosted: Tue Oct 20, 2009 11:55 pm    Post subject: Reply with quote

I workarounded this problem in a not very elegant way Sad:

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? Confused

Thanks in advance,
pauloricardo
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP