Method: PEROBS::Cache#evict

Defined in:
lib/perobs/Cache.rb

#evict(id) ⇒ True/False

Evict the object with the given ID from the cache.

Parameters:

  • id (Integer)

    ID of the cached PEROBS::ObjectBase

Returns:

  • (True/False)

    True if object was stored in the cache. False otherwise.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/perobs/Cache.rb', line 100

def evict(id)
  unless @transaction_stack.empty?
    PEROBS.log.fatal "You cannot evict entries during a transaction."
  end

  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 is in the write cache.
    @writes[idx] = nil
    return true
  elsif (obj = @reads[idx]) && obj._id == id
    # The object is in the read cache.
    @reads[idx] = nil
    return true
  end

  false
end