Class: RDF::Util::Cache::ObjectSpaceCache
- Inherits:
-
RDF::Util::Cache
- Object
- RDF::Util::Cache
- RDF::Util::Cache::ObjectSpaceCache
- Defined in:
- lib/rdf/util/cache.rb
Overview
This implementation relies on ObjectSpace#_id2ref
and performs
optimally on Ruby >= 2.x; however, it does not work on JRuby
by default since much ObjectSpace
functionality on that platform is
disabled unless the -X+O
startup option is given.
Instance Attribute Summary
Attributes inherited from RDF::Util::Cache
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#delete(key) ⇒ Object
Remove cache entry for key.
Methods inherited from RDF::Util::Cache
#capacity?, #initialize, #size
Constructor Details
This class inherits a constructor from RDF::Util::Cache
Instance Method Details
#[](key) ⇒ Object
73 74 75 76 77 |
# File 'lib/rdf/util/cache.rb', line 73 def [](key) if value_id = @cache[key] ObjectSpace._id2ref(value_id) rescue nil end end |
#[]=(key, value) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/rdf/util/cache.rb', line 83 def []=(key, value) if capacity? id = value.__id__ @cache[key] = id @index[id] = key ObjectSpace.define_finalizer(value, finalizer_proc) end value end |
#delete(key) ⇒ Object
Remove cache entry for key
98 99 100 101 102 |
# File 'lib/rdf/util/cache.rb', line 98 def delete(key) id = @cache[key] @cache.delete(key) @index.delete(id) if id end |