CodeIgniter Forums
Phil sturgeon's REST Server with memcached - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Phil sturgeon's REST Server with memcached (/thread-48267.html)



Phil sturgeon's REST Server with memcached - El Forum - 01-10-2012

[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


Phil sturgeon's REST Server with memcached - El Forum - 07-12-2012

[eluser]Peacemoon[/eluser]
STRANGE !!!! I have the same problem with trailing space characters in memcached.php . I try to delete the closed php tags ?> from memchached.php config file, the ajax call is very slow. Does anyone know why?