lib/perobs/Cache.rb in perobs-3.0.2 vs lib/perobs/Cache.rb in perobs-4.0.0
- old
+ new
@@ -93,23 +93,23 @@
end
end
# Return the PEROBS::Object with the specified ID or nil if not found.
# @param id [Integer] ID of the cached PEROBS::ObjectBase
- #def object_by_id(id)
- # idx = id & @mask
- # # The index is just a hash. We still need to check if the object IDs are
- # # actually the same before we can return the object.
- # if (obj = @writes[idx]) && obj._id == id
- # # The object was in the write cache.
- # return obj
- # elsif (obj = @reads[idx]) && obj._id == id
- # # The object was in the read cache.
- # return obj
- # end
+ def object_by_id(id)
+ idx = id & @mask
+ # The index is just a hash. We still need to check if the object IDs are
+ # actually the same before we can return the object.
+ if (obj = @writes[idx]) && obj._id == id
+ # The object was in the write cache.
+ return obj
+ elsif (obj = @reads[idx]) && obj._id == id
+ # The object was in the read cache.
+ return obj
+ end
- # nil
- #end
+ nil
+ end
# Flush all pending writes to the persistant storage back-end.
def flush
@writes.each { |w| w._sync if w }
@writes = ::Array.new(2 ** @bits)