skip to Main Content

I have this following code in the Address controller

public function index()
    {
        if($this->session->userdata('isLogin')) {
            $this->load->driver('cache');
            $this->load->model('MemberModel');
            if(!$this->cache->get('province') == false) {
                $this->load->model('ShippingModel');
                $data['provinces'] = $this->ShippingModel->the_provinces(); // it will return json object
                $this->cache->save('province', $data['provinces'], 300);
            } else {
                $data['provinces'] = $this->cache->get('province');
            }
            $userdata = $this->MemberModel->getProfile($this->session->userdata('userid'));
            $data['user'] = $userdata;

            $this->display_member_area('member/address', $data);
        }
        else {
            redirect(base_url());
        }
    }

When I want to get the data using:

var_dump($this->cache->get('province')); 

the result I get always shows

bool(false)

but when I tried to do this instead

var_dump($data['provinces']) // it's show me json object, that I want

Can anyone please show me where I’am doing wrong?

Thanks in advance

2

Answers


  1. Remove false from the if condition and use this code.

           if(!$this->cache->get('province')) {
                $this->load->model('ShippingModel');
                $data['provinces'] = $this->ShippingModel->the_provinces();
                $this->cache->save('province', $data['provinces'], 300);
            } else {
                $data['provinces'] = $this->cache->get('province');
            }
    
    Login or Signup to reply.
  2. Make sure you have the correct credential on your config at:

    https://github.com/bcit-ci/CodeIgniter/blob/develop/application/config/memcached.php

    it will be at you application/config/memcached.php file. Hostname is the ip you setup your memcached instance. You could provide multiple server if you wish.

    reference on installing memcached

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search