Friday 15 July 2011

ruby on rails - Youtube API Consumption & Caching -


I'm using the YouTube API. And this gem uses Net :: HTO as an adapter rather than directly using it. As you already know, take a remote request like this for at least a few seconds? Now that I do not have direct access to the Net :: HTTP library, how do I implement caching in my app? Here is a sample request to bring video from YouTube.

  #othentikeshn $ @claint = Yutubat :: Outh2Clientkni (Claint_akses_tokn: "Akses_tokn" Claint_rifres_tokn: "Rifres_tokn" Claint_id: "Claint_id" Claint_sikret: "Claint_sikret" Dev_ke " Dev_key ", expires_at:" expiration time ") #Request @ video = @ client.videos_by (: query =>" .penguin ") video # = & gt; Video Returns array of "<"> 

You possibly can do this, the combination of queries and penguins To close You have little to do its work and more rest, but I have found that it is usually better because caching is a ton of bugs when you can lead to turn it on too early for me to write my own caching .

Your code can:

  1. Check the video @ in your cache. Keyed by a combination of entry token and query
  2. If you remember any cache, then fetch and store the result in the cache.
  3. If there is a cache hit, then return back into cash. Deflected, and made him @ Store video

    A quick question: Is there any reason that you have a client an instance variable? You probably are in control and it does not require this approach, so as a general principle, you should limit the scope to provide their views.

No comments:

Post a Comment