Class: Rod::Cache::InternalMap
- Inherits:
-
Object
- Object
- Rod::Cache::InternalMap
- Includes:
- Singleton
- Defined in:
- lib/rod/cache.rb
Instance Attribute Summary collapse
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
-
#initialize ⇒ InternalMap
constructor
A new instance of InternalMap.
- #register(value, key, cache) ⇒ Object
Constructor Details
#initialize ⇒ InternalMap
Returns a new instance of InternalMap.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rod/cache.rb', line 9 def initialize @mutex = Mutex.new @object_to_caches = Hash.new{|h,v| h[v] = []} @finalizer = lambda do |object_id| @object_to_caches[object_id].each do |cache,key| cache.delete(key) end @object_to_caches.delete(object_id) end end |
Instance Attribute Details
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
7 8 9 |
# File 'lib/rod/cache.rb', line 7 def mutex @mutex end |
Instance Method Details
#register(value, key, cache) ⇒ Object
20 21 22 23 |
# File 'lib/rod/cache.rb', line 20 def register(value,key,cache) @object_to_caches[value.object_id] << [cache,key] ObjectSpace.define_finalizer(value,@finalizer) end |