Parrotmaster
Parrotmaster

Reputation: 676

$.ajax cache true duration

I'm trying to get a list of tweets (in this case 25 with a specific hashtag) using $.ajax and twitter's search functionality.

There's 2 things that are a bit unclear to me:

  1. How long is the duration for cache: true (how long does it take untill it sends a new request instead of using the cache)? At the moment it seems to be every few seconds but I'd like to know the precise duration and if/how this can be altered.

  2. This retrieving the information from twitter will be done by about 2000-3000 people at random moments, but probably not by that same person for a little while after. How will twitter respond to this (block the IP address because of too many requests maybe)? This is why I want to cache the information for about 1-5 minuutes, to lessen the amount of requests.

TL;DR: I'm making alot of requests to the twitter search functionality, how do I lessen the load?

Upvotes: 2

Views: 1017

Answers (1)

Andreas Hagen
Andreas Hagen

Reputation: 2345

The cache time for $.ajax is most likely browser dependant so you should not rely on this to balance your load against the Twitter API. This caching can be turned off by passing { cache: false } into the settings parameter. Instead you should implement your own cacheing system.

Twitter has a page describing this: https://dev.twitter.com/docs/rate-limiting.

It says that it sends some headers to tell you how many requests you have left within a certain timespan. What you will have to do is just cache long enough so that you do no exceed the limits Twitter imposes on you. You should do some testing to see how different load on your service will affect the total number of calls to the Twitter API and design your cache system accordingly. The most optimal solution here will probably be something like from a to b'o-clock i will need to cache for c minutes and from d to e'o-clock i will need to cache for f minutes. Another solution might be to implement a system to keep track of load as it is happening and determine cache times in real time. If both of these solutions seams to daunting you can probably get away with just picking a long enough cache time so that you will never exceed the limit.

Upvotes: 1

Related Questions