Class: EntityCache::Storage::Temporary::Scope::Shared

Inherits:
EntityCache::Storage::Temporary show all
Defined in:
lib/entity_cache/storage/temporary/scope/shared.rb

Instance Attribute Summary

Attributes inherited from EntityCache::Storage::Temporary

#subject

Instance Method Summary collapse

Methods inherited from EntityCache::Storage::Temporary

build, configure, #get, #initialize, #put

Constructor Details

This class inherits a constructor from EntityCache::Storage::Temporary

Instance Method Details

#records ⇒ Object



6
7
8
# File 'lib/entity_cache/storage/temporary/scope/shared.rb', line 6

def records
  subject_registry[subject] ||= {}
end

#subject_registry ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/entity_cache/storage/temporary/scope/shared.rb', line 10

def subject_registry
  current_thread = Thread.current

  if current_thread.thread_variable?(thread_local_variable)
    subject_registry = current_thread.thread_variable_get(thread_local_variable)
  else
    subject_registry = {}

    current_thread.thread_variable_set(thread_local_variable, subject_registry)
  end

  subject_registry
end

#thread_local_variable ⇒ Object



24
25
26
# File 'lib/entity_cache/storage/temporary/scope/shared.rb', line 24

def thread_local_variable
  :entity_cache_subject_registry
end