views:

29

answers:

2

In a project I'm working on, I'm requesting data from an external API in my controller, which is then displayed in the view. I've recently begun running into exceptions being thrown due to rate limits, which are caused from excessive calls to the API. To fix this, I'm assuming that I need to implement some sort of caching system. I've been reading up on page caching in rails, and it doesn't seem to solve my problem, since I'm not using models from my own database. So, I was wondering if there was a simple way to cache the page on a timed basis, so that new data could be requested through the API every so often.

Hope this makes sense--I'm fairly new to Ruby on Rails, and I've never worked with any sort of caching system before.

+1  A: 

There doesn't seem to be a built-in mechanism for this. You could try this user's solution, though.

Matchu
+3  A: 

Memcached has the time-based expiration you're talking about, and is quite excellent for caching most common objects, including pages, I believe.

It's really easy to install and Rails comes ready to use it a with one-line configuration for memcached.

The following screencast was very helpful for learning about memcached:

http://railslab.newrelic.com/2009/02/19/episode-8-memcached

Actually, I recommend the entire series, as it's tremendously useful.

Here's the memcached site:

http://memcached.org

If you're more a manual type, you could always create a cron job that runs once every few minutes and generates the new file.

Hope this helps!

btelles
thanks--this seems to be what I'm looking for
mportiz08