Class: ROM::Cache Private

Inherits:
Object
  • Object
show all
Defined in:
core/lib/rom/cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Thread-safe cache used by various rom components

Entries are keyed by the arguments themselves rather than by their #hash, so two keys whose hashes collide are still told apart by #eql?. JRuby's Hash#hash collides for hashes that differ only by a module, which is how relation ASTs differ by struct namespace.

Defined Under Namespace

Classes: Namespaced

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Cache.



46
47
48
49
# File 'core/lib/rom/cache.rb', line 46

def initialize
  @objects = ::Concurrent::Map.new
  @namespaced = {}
end

Instance Attribute Details

#objects ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'core/lib/rom/cache.rb', line 14

def objects
  @objects
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
# File 'core/lib/rom/cache.rb', line 51

def [](key) = objects[key]

#fetch_or_store(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
# File 'core/lib/rom/cache.rb', line 54

def fetch_or_store(*args, &) = objects.fetch_or_store(args, &)

#inspect ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'core/lib/rom/cache.rb', line 65

def inspect
  %(#<#{self.class} size=#{size} namespaced=#{@namespaced.inspect}>)
end

#namespaced(namespace) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
# File 'core/lib/rom/cache.rb', line 60

def namespaced(namespace)
  @namespaced[namespace] ||= Namespaced.new(objects, namespace)
end

#size ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
# File 'core/lib/rom/cache.rb', line 57

def size = objects.size