Method: PEROBS::Cache#cache_write
- Defined in:
- lib/perobs/Cache.rb
#cache_write(obj) ⇒ Object
Add a PEROBS::Object to the write cache.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/perobs/Cache.rb', line 66 def cache_write(obj) # This is just a safety check. It can probably be disabled in the future # to increase performance. #if obj.respond_to?(:is_poxreference?) # # If this condition triggers, we have a bug in the library. # PEROBS.log.fatal "POXReference objects should never be cached" #end if @transaction_stack.empty? # We are not in transaction mode. idx = index(obj) if (old_obj = @writes[idx]) && old_obj._id != obj._id # There is another old object using this cache slot. Before we can # re-use the slot, we need to sync it to the permanent storage. old_obj._sync end @writes[idx] = obj else # When a transaction is active, we don't have a write cache. The read # cache is used to speed up access to recently used objects. cache_read(obj) # Push the reference of the modified object into the write buffer for # this transaction level. unless @transaction_stack.last.include?(obj._id) @transaction_stack.last << obj._id @transaction_objects[obj._id] = obj end end end |