4

I'm try to use the Codeigniter cache system, to cache some remote xml files into "file cache".

Every think looks great when I request the xmls, but codeigniter not cache the files, instead it return a empty cache, and the cache file contains just the data below:

a:3:{s:4:"time";i:1379515910;s:3:"ttl";i:120;s:4:"data";b:1;}

I'm using the code below to cache the xml:

$this->load->driver('cache');
$this->cache->file->save('first', $data, 120);

[UPDATED]

Now I can save the cache, but I can't rescue the saved data. When I run the command below the cache return false

$this->cache->get('show');

Where am I going wrong?

Thanks.

4
  • What does $this->cache->file->save('first', $data, 120); return? If the save fails it will return false. Have you tried saving something simple to the cache like a string to check if it's working? Commented Sep 20, 2013 at 14:20
  • have you checked logs and permissions? Could be a permission issue. Commented Sep 20, 2013 at 15:16
  • I did, the log not show errors and the cache directory permissions is 777. I can save the cache, but I can't get it back. Commented Sep 20, 2013 at 15:21
  • Have you tried $this->cache->get('first'); to get the data back? Commented Sep 20, 2013 at 15:38

6 Answers 6

4

Problem solved, when I call the method to get the current cache I need to pass the used driver e.g.:

$this->cache->file->get('home');
OR
$this->cache->memcached->get('home');

Thanks.

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

2 Comments

where is the 'home' comes from? Could you explain the detail? I got the same issue, always return false when get the cached file.
This makes no sense. Your code above saves the item as first, your original post tries to fetch a cache item named show, and your solution fetches an item named home. This answer is not good.
4

You've saved it using

$this->cache->file->save('first', $data, 120);

Then get it using the right key and it should be first

$this->cache->get('first');

Also, to get information about cache you can use

var_dump($this->cache->cache_info());

Or you may use

var_dump($this->cache->get_metadata('first'));

This is useful for debugging. The get method accepts cache_item_id as parameter that you have used when you saved it

get(id['string'])

Check the documentation.

1 Comment

The documentation link is broken.
2

Just create folder "cache" in "application" directory. It works for me

1 Comment

The best thing is to check whether the cache folder exists as you mentioned.
0

I had same problem but in my case it was storage problems.

my hdd was 100% full (because of some error logs).

Maybe this information will help someone.

Comments

0

I stumbled here with similar issue. My problem was that APC cache wasn't installed. So if anyone else is using APC and having this issue. Try installing APC.

Example PHP 7.1 on ubuntu 1604:

sudo apt-get update
sudo apt-get install php7.1-apcu
sudo service php7.1-fpm restart

Comments

0

I get same problem too ...

$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
$this->cache->file->save('first', $data, 120);

I modified these two lines..

Comments

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.