I need to know if I can improve the way to cache my api calls from inside my CodeIgniter application. As I am doing this right now, this is the hmvc template:
- Controller
HOME == causes => module app/application/modules/apis/controllers/c_$api == loads the library => > app/application/libraries/$api==> Library returns the response to the module controller_X, the controller causes a representation of the data that it has
//Note. My application does not use twitter api, but others
Inside the module apisis all apc caching, for example:
$this->load->library('driver');
$this->load->driver('cache', array('adapter' => 'apc'));
$tweets = $this->cache->get('my_tweets');
if ( ! $tweets)
{
$url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=gaker&count=5';
$tweets = json_decode(file_get_contents($url));
$this->cache->save('my_tweets',$tweets, 300);
}
return $tweets;
as described in this article: http://www.gregaker.net/2011/feb/12/codeigniter-reactors-caching-drivers/
Therefore, I was wondering:
3 : home, query, result; apis, , ? :
$this->cache->save('api_home',$api_home, 300);
$this->cache->save("api_$query", $api_{$query}, 300);
$this->cache->save("api_$queryId", $api_{$queryId}, 300);
api, , , api, 3 (home, query result)? :
$homeData['latest'][$api] = modules::run("apis/c_$api/data", array('action'=>'topRated'));
$this->cache->save('home_data', $home_data, 300);
$searchResults[$api] = modules::run("apis/c_$api/data", $parameters);
$this->cache->save("search_results_$query", $search_results_{$query}, 300);
$result = modules::run("apis/c_$api/data", $parameters);
$this->cache->save("$api_article_$id", ${$api}_article_{$id}, 300);
, ? , , ?
// , ... , ${$api}_article_{$id} (, , )