paquettg / leaguewrap

League of Legend API wrapper
MIT License
67 stars 28 forks source link

Cache Questions #77

Closed archer3cl closed 9 years ago

archer3cl commented 9 years ago

Hi! Im trying to learn how to use the cache on this wrap. Memcached is already set so thers no problem on that.

Im retrieving the matches using

$game       = $api->game();
$games      = $game->recent($summoner_id);

So lets say i want to cache this response for an hour and any new call to that same request just read the cache and dont make a new call.

I know it has to do something with

->remember(3600) and ->setCacheOnly() but i just dont make it to work.

EDIT: Is this the way?

try{
    return $this->api->game()->setCacheOnly()->recent($summoner);
}catch(\Exception $e){
    return $this->api->game()->remember(3600)->recent($summoner);
}

This is suppose to do "Retrieve matches from cache if fails then do the call and remember for an hour"

Thanks for helping

dnlbauer commented 9 years ago

You dont need the setCachedOnly().

Its enough to do $this->api->game()->remember(3600)->recent($summoner);

if there is a cached value younger than 3600, you will get that result. If not, a new request will be dispached.

archer3cl commented 9 years ago

thanks. You are always helping me