Class: RightSharding::ShardHandler::CurrentRequestCache

Inherits:
Object
  • Object
show all
Defined in:
lib/right_sharding/shard_handler.rb

Overview


CurrentRequestCache - caching data only for this request

Constant Summary collapse

CACHE_ID =
:right_sharding_current_request_cache

Class Method Summary collapse

Class Method Details

.destroyObject



115
116
117
# File 'lib/right_sharding/shard_handler.rb', line 115

def self.destroy
  Thread.current[CACHE_ID] = nil
end

.find_or_save_shard_map(account_id, value_proc) ⇒ Object



123
124
125
# File 'lib/right_sharding/shard_handler.rb', line 123

def self.find_or_save_shard_map(, value_proc)
  Thread.current[CACHE_ID]["shard_map"][] ||= value_proc.call
end

.find_or_save_this_shard(value_proc) ⇒ Object



131
132
133
# File 'lib/right_sharding/shard_handler.rb', line 131

def self.find_or_save_this_shard(value_proc)
  Thread.current[CACHE_ID]["this_shard"] ||= value_proc.call
end

.find_or_save_this_shard_id(value_proc) ⇒ Object



127
128
129
# File 'lib/right_sharding/shard_handler.rb', line 127

def self.find_or_save_this_shard_id(value_proc)
  Thread.current[CACHE_ID]["this_shard_id"] ||= value_proc.call
end

.initObject



108
109
110
111
112
113
# File 'lib/right_sharding/shard_handler.rb', line 108

def self.init
  Thread.current[CACHE_ID] = {}

  Thread.current[CACHE_ID]["shard_map"]     = {}
  Thread.current[CACHE_ID]["this_shard_id"] = nil
end

.is_activated?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/right_sharding/shard_handler.rb', line 119

def self.is_activated?
  !Thread.current[CACHE_ID].nil?
end