Rate Limit Calls To Api Using Cache

Posted by namtax on Stack Overflow See other posts from Stack Overflow or by namtax
Published on 2010-04-26T09:12:44Z Indexed on 2010/04/26 9:13 UTC
Read the original article Hit count: 242

Filed under:
|
|
|

Hi I am using coldfusion to call the last.fm api, using a cfc bundle sourced from here

I am concerned about going over the request limit, which is 5 requests per originating IP address per second, averaged over a 5 minute period.

The cfc bundle has a central component which calls all the other components, which are split up into sections like "artist", "track" etc...This central component "lastFmApi.cfc." is initiated in my application, and persisted for the lifespan of the application

// Application.cfc example
    <cffunction name="onApplicationStart">
        <cfset var apiKey = '[your api key here]' />
        <cfset var apiSecret = '[your api secret here]' />

        <cfset application.lastFm = CreateObject('component', 'org.FrankFusion.lastFm.lastFmApi').init(apiKey, apiSecret) />
    </cffunction>

Now if I want to call the api through a handler/controller, for example my artist handler...I can do this

<cffunction name="artistPage" cache="5 mins">
 <cfset qAlbums = application.lastFm.user.getArtist(url.artistName) />
</cffunction>

I am a bit confused towards caching, but am caching each call to the api in this handler for 5 mins, but does this make any difference, because each time someone hits a new artist page wont this still count as a fresh hit against the api?

Wondering how best to tackle this

Thanks

© Stack Overflow or respective owner

Related posts about rate-limiting

Related posts about api