Class: Cachext::Multi

Inherits:
Object
  • Object
show all
Defined in:
lib/cachext/multi.rb

Defined Under Namespace

Classes: FindByIds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, key_base, options = {}) ⇒ Multi

Returns a new instance of Multi.



9
10
11
12
13
# File 'lib/cachext/multi.rb', line 9

def initialize config, key_base, options = {}
  @config = config
  @key_base = key_base
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/cachext/multi.rb', line 7

def config
  @config
end

#key_baseObject (readonly)

Returns the value of attribute key_base.



7
8
9
# File 'lib/cachext/multi.rb', line 7

def key_base
  @key_base
end

Instance Method Details

#expires_inObject



29
30
31
# File 'lib/cachext/multi.rb', line 29

def expires_in
  @options.fetch :expires_in, @config.default_expires_in
end

#fetch(ids, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cachext/multi.rb', line 15

def fetch ids, &block
  records = FindByIds.new(self, ids, block).records

  if @options.fetch(:return_array, false)
    records.values + missing_records(ids - records.keys)
  else
    records
  end
end

#heartbeat_expiresObject



33
34
35
# File 'lib/cachext/multi.rb', line 33

def heartbeat_expires
  @options.fetch :heartbeat_expires, config.heartbeat_expires
end

#key(id) ⇒ Object



25
26
27
# File 'lib/cachext/multi.rb', line 25

def key id
  @key_base + [id]
end