php - Codeigniter: DB Cache check if record loaded from Database OR from Cache -


i'm implementing db cache in codeigniter , want check if record or cache file exists against query.

as far read codeigniter documentation probably, there no way check it. so, can give me hint if possible?

here flowchart achieve

if (!$this->db->query_exists("query here"))     // something. query doesn't exists in cache  // run query in case $this->db->query("query here"); 

thank you!

it unclear why need/want this. assuming query caching enabled, codeigniter db driver checking , use cached query if exists or perform query , cache if not. main thing have implement clearing appropriate cache when perform record inserts, updates, or deletions invalidate cached results.

that said, easiest way determine if cache exists ci_db_cache::read($sql) method. method returns false if matching cache file not found.

the db driver has public property - $cache. (yes, it's uppercase variable name.) $cache instance of ci_db_cache class.

this property defined after read type query has been performed. "catch 22" - can't check cache file until read query performed, want check before performing one.

take @ protected function _cache_init() in /system/database/db_driver.php see how ci_db_cache class instantiated. might need implement same sort of thing in code.

you might find useful see how $this->cache used in public function query($sql, $binds = false, $return_object = null) in /system/database/db_driver.php.

you might able determine if query in question exists using approach follows. might because have not tested this.

$sql = "select * some_table"; //check cache defined if(isset($this->db->cache)) {     $query = $this->db->cache->read($sql);      if($query === false)     {          // something. query doesn't exists in cache     } } 

$query query result object if cache found.

however, have delete cache before can accomplish

// run query in case $this->db->query("query here"); 

without delete you're going end same query result object have retrieved.

keep in mind caching class dependent on uri being requested browser. caching uses first 2 uri segments (controller class name , function name) determine folder holds cache file.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -