0

I have a problem parsing an RSS feed. When I do this:

  feed = getFeed("http://example.com/rss)

If the feed content changes it don't update.

If I do it like this:

feed = getFeed("http://example.com/rss?" + Random.rand(20).to_s)

It works most of the time but not always.

getFeed() is implemented like this:

def getFeed(url)
   rss_content = ""
   open(url) do |f|
      rss_content = f.read
   end
   return rss_content
end

I used this in Sinatra with Ruby 1.9.3, if this make a difference. On my opinion somewhere it gets cached but I have no idea where.

Edit: Okey after 1/2 day running on the server it works with out a problem.

Sir l33tname
  • 4,026
  • 6
  • 38
  • 49

1 Answers1

2

This:

feed = getFeed("http://example.com/rss?" + Random.rand(20).to_s)

implies the problem is with caching, but Ruby, OpenURI and Sinatra shouldn't be caching anything. Perhaps your code is running behind a caching device or app that is handling outgoing requests as well as incoming?

This isn't the fix, but your code can be streamlined greatly:

def getFeed(url)
  open(url).read
end
the Tin Man
  • 158,662
  • 42
  • 215
  • 303