0

I want to turn on database caching into my CodeIgniter website for this I have used following code in database.php file.

    $db['default']['cache_on'] = FALSE;  
    $db['default']['cachedir'] = 'application.cache';

And I have already created a folder, name cache inside application directory and give permission 0777.

when I run my website, it shows error - this web page isn't working.
the same code is perfect works on my localhost (xampp server).

Did I forget to include anything? Please help me out

1 Answer 1

1

You have to use a relative path instead of '.'[dot].

But if you want to enabled database query caching then make your 'cache_on' to TRUE

$db['default']['cache_on'] = TRUE;  
$db['default']['cachedir'] = 'application/cache';

if above line not works try this:

$db['default']['cachedir'] = APPPATH . 'cache';

After that whichever query you want to store in cache use this feature

 // Turn caching on
 $this->db->cache_on();

 // Turn caching off for this one query
 $this->db->cache_off();

Notes:

  • CodeIgniter’s query caching system happens dynamically when your pages are viewed. When caching is enabled, the first time a web page is loaded, the query result object will be serialized and stored in a text file on your server. The next time the page is loaded the cache file will be used instead of accessing your database.
  • Only read-type (SELECT) queries can be cached not Write-type (INSERT, UPDATE, etc.) queries

The caching system permits you clear caches So whenever DB updated clear related catching also.When the page loaded it again caching updated queries.

Read this for deleting caching

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, how can we use this if we want to display updated data also? Whenever I want to see updated data I have to delete the cache files inside cache folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.