Skip to content

Commit

Permalink
Simple instance variable caching.
Browse files Browse the repository at this point in the history
The problem with the last commit is that we ended up making a LOT MORE
requests than we should have, due to making excessive XML objects. Then
inside of the XML object, we referred to the virtual attribute that
makes a Request multiple times. Ack! Now we don't do that any more.

Note that HTTP caching would be the 'right' thing to do here. I don't
want to get into that yet, so we're just using instance variables.
  • Loading branch information
steveklabnik committed Dec 7, 2011
1 parent 206a9e1 commit bf52b1f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions maze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class Room
def initialize(uri)
@xml ||= {}
@uri = uri
@uri = xml.extract_href('start')
end
Expand All @@ -23,7 +24,7 @@ def finished?
private

def xml
XML.new(@uri)
@xml[@uri] ||= XML.new(@uri)
end
end

Expand All @@ -33,7 +34,7 @@ def initialize(uri)
end

def current
Request.new(@uri).get
@request ||= Request.new(@uri).get
end

def extract_href(rel)
Expand Down

0 comments on commit bf52b1f

Please sign in to comment.