[eluser]Pedro Correia[/eluser]
I've been trying to create a simple REST api for a small project i have going on, using Phils REST Server and it works just fine, except when i tried to integrate memcached to cache database result objects.
I have this simple example:
Code:
// check if the object is in cache
if(!$this->cache->memcached->get($cachekey)){
// load the posts model
$this->load->model('Posts_API_model','MPosts');
// get the data from the database
if($posts = $this->MPosts->getPostList($type,$page,$limit))
{
// we have a dataset from the database, let's save it to memcached
$this->cache->memcached->save($cachekey,$posts,10*60);
// output the response
$this->response($posts);
} else {
// we got nothing to show, output error
$this->response(array('status'=>false,'message'=>'Fatal error: No data from cache or database.'),404);
}
// the object is cached, send it
} else {
$cache = $this->cache->memcached->get($cachekey);
$this->response($cache);
}
If i take out the caching part it works great and i get, as i request a perfectly formated json string.
When using caching i get a whitespace before the json string in the response body rendering the request invalid to a REST client.
I've scoured the code up and down and found out that commenting out the code that sets the 'Content-Type' header in the REST_Controller, makes the damned whitespace go away, but that's not really a proper fix.
Can anyone shed some light on this problem please?
Thank you in advance,
Pedro