                 if time? and x.time > time
                     break
                 value = apply_patch(x.patch, value)[0]
-
-        if not time? and x?   # x? = there was at least one new patch
-            @_cache = {patch:x, value:value, start:@_patches.length, last_snapshot:last_snapshot}
+                if not time?
+                    cache_time = x.patch.time
+
+        if cache_time
+            @_cache = {time:cache_time, value:value, start:@_patches.length}
 
         return value
 

            # newer than latest snapshot),
            # then clear cache, since can't build on it
            for x in v
                if @_cache.last_snapshot - 0 <= x.time - 0 <= @_cache.patch.time - 0
                    delete @_cache
                    break
        # this is O(n*log(n)) where n is the length of @_patches and patches;

            return
        v = []
        for x in patches
            if x? and (not @_times[x.time - 0] or (x.snapshot? and not @_snapshot_times[x.time - 0]))
                v.push(x)
                @_times[x.time - 0] = true
                if x.snapshot?
