Defining Good Caching Scenarios

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:

    // Load up drivers
    $this->load->library('driver');
    $this->load->driver('cache', array('adapter' => 'apc'));

    // Get Tweets from Cache
    $tweets = $this->cache->get('my_tweets');

    if ( ! $tweets)
    {
        // No tweets in the cache, so get new ones.
        $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, , ? :

    //for each api1, api2 ... apiX, apply this:
    
    //home
    $this->cache->save('api_home',$api_home, 300);
    
    //query
    $this->cache->save("api_$query", $api_{$query}, 300); // I don't know for sure if $api_{$query} works or not, so don't hang me because I haven't tried it.
    
    //result
    $this->cache->save("api_$queryId", $api_{$queryId}, 300);
    
  • api, , , api, 3 (home, query result)? :

    //modules/{home,fetch,article}/controllers/{home,fetch,article}.php
    
    //home
    $homeData['latest'][$api]   = modules::run("apis/c_$api/data", array('action'=>'topRated'));
    $this->cache->save('home_data', $home_data, 300);
    
    //query
    $searchResults[$api] = modules::run("apis/c_$api/data", $parameters);
    $this->cache->save("search_results_$query", $search_results_{$query}, 300);
    
    //article page
    $result = modules::run("apis/c_$api/data", $parameters);
    $this->cache->save("$api_article_$id", ${$api}_article_{$id}, 300);
    

, ? , , ?

// , ... , ${$api}_article_{$id} (, , )

+3
1

IMHO api, . , , , , . : " ?" .

: , . . api, , , .

( ), - Varnish CloudFront.

+1

All Articles