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 1.8.x and 1.9.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 Method Summary collapse
Methods inherited from RDF::Util::Cache
#define_finalizer!, #finalizer, #has_capacity?, #initialize, new, #size
Constructor Details
This class inherits a constructor from RDF::Util::Cache
Instance Method Details
#[](key) ⇒ Object
82 83 84 85 86 |
# File 'lib/rdf/util/cache.rb', line 82 def [](key) if value_id = @cache[key] value = ObjectSpace._id2ref(value_id) rescue nil end end |
#[]=(key, value) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/rdf/util/cache.rb', line 92 def []=(key, value) if has_capacity? @cache[key] = value.__id__ @index[value.__id__] = key define_finalizer!(value) end value end |