<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,27 +16,16 @@ get %r{/api/v1/fibonacci/([\d]+)} do
 end 
 
 def fib(n)
-  fib_n = CACHE.get(n)
-  unless fib_n
+  CACHE.get(n) || begin
     return n if (0..1).include? n
 
-    n_1 = CACHE.get(n - 1)
-    unless n_1
-      n_1 = fib(n - 1)
-      CACHE.set(n - 1, n_1)
-    end
+    n_1 = CACHE.get(n - 1) || fib(n - 1)
+    n_2 = CACHE.get(n - 2) || fib(n - 2)
 
-    n_2 = CACHE.get(n - 2)
-    unless n_2 
-      n_2 = fib(n - 2)
-      CACHE.set(n - 2, n_2)
-    end
-
-    fib_n = n_1 + n_2
-    CACHE.set(n, fib_n)
+    result = n_1 + n_2
+    CACHE.add(n, result)
+    result
   end
-
-  fib_n
 end
 
 __END__</diff>
      <filename>init.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>50adcd63e7561b6eed9085166dd4bf70088d0b3c</id>
    </parent>
  </parents>
  <author>
    <name>Josh Nichols</name>
    <email>josh@technicalpickles.com</email>
  </author>
  <url>http://github.com/technicalpickles/ifib/commit/1355ac60068dfb7bf6ca9b0723e407b34cd5916b</url>
  <id>1355ac60068dfb7bf6ca9b0723e407b34cd5916b</id>
  <committed-date>2009-01-26T15:01:43-08:00</committed-date>
  <authored-date>2009-01-26T15:01:43-08:00</authored-date>
  <message>Cleaned up flow, and use CACHE.add instead of CACHE.get</message>
  <tree>e5e42fa69e77aaaecb77cb170ea0aaa2902adf80</tree>
  <committer>
    <name>Josh Nichols</name>
    <email>josh@technicalpickles.com</email>
  </committer>
</commit>
