Memcached does not completely cache
Background on my installation: As I did this in a haste, I installed memcached through apt-get / Didn't compile by source. Then I just ran "memcached -d -m 512 -p 11211"
I wrote this example code:
//....some code before, getting the $view object, etc...
if ( isset($_GET['set']) )
\Cache::set('memcached_test', 'testing!', 3600 * 3);
try {
$view->cache_test_data = \Cache::get('memcached_test');
$view->cache_test = true;
} catch (\Cache_Exception $e) {
$view->cache_test = false;
$view->cache_test_data = '(null)';
}
//the rest of the code, aka outputting.
Now, first I accessed the default controller with /?set. It worked, and I got the data I set. However, when I don't set it before I get the data, it marks the test as failed. I have also tried without Fuel, and it worked perfectly.
If you're getting a Cache_Exception thrown, there's an issue in the driver, as this should be handled internally and return false.
The exception is "not found". Which is weird, because when I set it and I got the data, it worked. But not when I don't set it.
Isn't it logical that you get a 'not found' if you try to get it, but it's not set?
Sorry, by that I mean:
1st page load: Set the cache (for 3 hours) + get the cache value 2nd page load: Get the cache, but it returns not found.
Can't reproduce it here. Used a stock install of Fuel, and added this to the welcome controller:
/**
* Test the Cache class
*/
public function action_cache1()
{
Cache::set('test', 'String to be cached.', 3600 * 3);
echo Debug::dump(Session::get('test'));
echo Html::anchor('test/cache2', 'Test cache');
$this->response->body = '<br /><br /><hr />TEST CONTROLLER - CACHE1 METHOD';
}
public function action_cache2()
{
try
{
echo Debug::dump(Cache::get('test'));
}
catch (\Exception $e)
{
echo "can't retrieve \"test\" variable from cache!";
}
$this->response->body = '<br /><br /><hr />TEST CONTROLLER - CACHE2 METHOD';
}
Use http://website/welcome/cache1 to set it, http://website/welcome/cache2 to read it back. Works without issues here.
/**
* Test the Cache class
*/
public function action_cache1()
{
$data = array(
'id' => 1,
'stuff' => 2,
'username' => 'System'
);
Cache::set('test_test1', $data, 3600 * 3);
Cache::set('test_test2', $data, 3600 * 3);
Cache::set('test_test3', $data, 3600 * 3);
echo Debug::dump(
Cache::get('test_test1'),
Cache::get('test_test2'),
Cache::get('test_test3')
);
echo Html::anchor('welcome/cache2', 'Test cache');
$this->response->body = '<br /><br /><hr />TEST CONTROLLER - CACHE1 METHOD';
}
public function action_cache2()
{
try
{
echo Debug::dump(Cache::get('test_test1'), Cache::get('test_test2'), Cache::get('test_test3'));
}
catch (Cache_Exception $e)
{
echo "failed!";
}
$this->response->body = '<br /><br /><hr />TEST CONTROLLER - CACHE2 METHOD';
}
Fails, (Fuel\Core\Cache_Exception [ Error ]: not found). Maybe its an issue setting multiple cache items at once? I remove in Debug::dump "test_test1" and "test_test2", and it works...