• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phil sturgeon's REST Server with memcached

#1
[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

#2
[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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.