Cache is not working

49 views
Skip to first unread message

Muhammad Shahzad

unread,
Oct 17, 2017, 5:21:41 AM10/17/17
to f3-fra...@googlegroups.com
Hi,

Cache is not woking in my app, I'm fetching some data from database then setting into f3 set after that whenever I tried to fetch that data it comes from database not from cache? what is the issue?


index.php
$f3->mset(array(
     
...
       
"CACHE" => true,
...


Controller:

  public function index($f3) {

        $currencySymbols
= \Helper\Master::getAllCurrencySymbolsCultureWise($f3);
        echo
"<pre>";
        print_r
($currencySymbols);
       
exit;

\Helper\Master

 
/*
    * Get All currency symbols cultures wise
    * @Usage: \Helper\Master::getAllCurrencySymbolsCultureWise();
    */

   
public function getAllCurrencySymbolsCultureWise($f3){
       
//$f3 = \Base::instance();
       
if($f3->exists('currencySymbols')){

            $rows
= $f3->get('currencySymbols');
            $rows
[]='Return from f3 cache';
         
       
}else{
            $sql
= "SELECT culture.cultureid, currency.symbol
                        FROM s_culture culture
                        INNER JOIN s_currency currency ON culture.currencyid = currency.currencyid"
;
            $rows
= $f3->get('db.instance')
                   
->exec($sql);
            $rows
[]='Return from fresh query';
            $f3
->set('currencySymbols', $rows);
       
}
       
return $rows;
   
}


It always print data 'Return from fresh query', there is an empty folder  tmp/cache, but nothing being stored in cache folder, any idea what am I doing wrong?

ved

unread,
Oct 17, 2017, 8:49:54 AM10/17/17
to Fat-Free Framework
At no point in your example code I see a $ttl parameter. So you're not using cache at all. You'd have to use something like:

$f3->set('currencySymbols', $rows, 600);  // cache for 600 seconds

Anyway, please read the documentation on caching where it's pretty well explained.

Muhammad Shahzad

unread,
Oct 18, 2017, 12:58:48 AM10/18/17
to Fat-Free Framework
Hi,

Thank you for your reply, can you pls tell me $ttl stands for?(abbreviation)

ved

unread,
Oct 18, 2017, 3:44:51 AM10/18/17
to Fat-Free Framework
Hi, it's an abbreviation for time-to-live. See here.

Muhammad Shahzad

unread,
Oct 18, 2017, 5:17:02 AM10/18/17
to Fat-Free Framework
Thank you for your cooperation.
Reply all
Reply to author
Forward
0 new messages