CodeIgniter Forums
Cache database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Cache database (/showthread.php?tid=70632)



Cache database - omid_student - 05-05-2018

Hi
I use $this->db->cache_on for cache my query
But when i execute query,it dont save query sometimes
What is problem?


RE: Cache database - php_rocs - 05-11-2018

(05-05-2018, 11:50 AM)omid_student Wrote: Hi
I use $this->db->cache_on for cache my query
But when i execute query,it dont save query sometimes
What is problem?

Is it possible to see the code around this statement?  It would allow us to better assess the issue or problem.


RE: Cache database - omid_student - 05-12-2018

(05-11-2018, 08:42 AM)php_rocs Wrote:
(05-05-2018, 11:50 AM)omid_student Wrote: Hi
I use $this->db->cache_on for cache my query
But when i execute query,it dont save query sometimes
What is problem?

Is it possible to see the code around this statement?  It would allow us to better assess the issue or problem.
Yes
Here:
PHP Code:
        public function delete_cache_file($query,$segment_one ''$segment_two '')
        {
            if (
$segment_one === '')
            {
                
$segment_one  = ($this->uri->segment(1) == FALSE) ? 'default' $this->uri->segment(1);
            }

            if (
$segment_two === '')
            {
                
$segment_two = ($this->uri->segment(2) == FALSE) ? 'index' $this->uri->segment(2);
            }

            
$file_path $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($query);
            @
unlink($file_path);
        } 



RE: Cache database - omid_student - 05-12-2018

(05-12-2018, 12:58 AM)omid_student Wrote:
(05-11-2018, 08:42 AM)php_rocs Wrote:
(05-05-2018, 11:50 AM)omid_student Wrote: Hi
I use $this->db->cache_on for cache my query
But when i execute query,it dont save query sometimes
What is problem?

Is it possible to see the code around this statement?  It would allow us to better assess the issue or problem.
Yes
Here:
PHP Code:
public function delete_cache_file($query,$segment_one ''$segment_two '')
 {
 if (
$segment_one === '')
 {
 
$segment_one  = ($this->uri->segment(1) == FALSE) ? 'default' $this->uri->segment(1);
 }

 if (
$segment_two === '')
 {
 
$segment_two = ($this->uri->segment(2) == FALSE) ? 'index' $this->uri->segment(2);
 }

 
$file_path $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($query);
 @
unlink($file_path);
 } 

Actually i get query string and md5 it and combine with segments and delete file


RE: Cache database - php_rocs - 05-16-2018

@omid_student,

Also, have you checked the CI/Apache log to see if there were error messages? I also noticed that you are suppressing errors "@unlink". Maybe for testing purposes you should not suppress errors.


RE: Cache database - omid_student - 05-16-2018

(05-16-2018, 07:35 AM)php_rocs Wrote: @omid_student,

Also, have you checked the CI/Apache log to see if there were error messages?  I also noticed that you are suppressing errors "@unlink".  Maybe for testing purposes you should not suppress errors.

Why log?
My code have no error


RE: Cache database - php_rocs - 05-16-2018

@omid_student,
Maybe it threw a error/warning when it tried to delete the file but was unable to.


RE: Cache database - omid_student - 05-16-2018

(05-16-2018, 01:12 PM)php_rocs Wrote: @omid_student,
Maybe it threw a error/warning when it tried to delete the file but was unable to.

I can check file existing or not
Or add @ before unlink Blush


RE: Cache database - php_rocs - 05-17-2018

(05-16-2018, 11:25 PM)omid_student Wrote:
(05-16-2018, 01:12 PM)php_rocs Wrote: @omid_student,
Maybe it threw a error/warning when it tried to delete the file but was unable to.

I can check file existing or not
Or add @ before unlink  Blush

I would remove @ before unlink. I try not to suppress errors. This way the errors should be logged.


RE: Cache database - omid_student - 05-17-2018

(05-17-2018, 11:02 AM)php_rocs Wrote:
(05-16-2018, 11:25 PM)omid_student Wrote:
(05-16-2018, 01:12 PM)php_rocs Wrote: @omid_student,
Maybe it threw a error/warning when it tried to delete the file but was unable to.

I can check file existing or not
Or add @ before unlink  Blush

I would remove @ before unlink.  I try not to suppress errors.  This way the errors should be logged.

Yes you are right