Class: Dragonfly::Cache::Manager

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dragonfly/cache/manager.rb

Constant Summary collapse

MIN_SHA_SIZE =
2
MAX_SHA_SIZE =

Length of SHA identifier generated by Dragonfly

16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin) ⇒ Manager

Returns a new instance of Manager.



18
19
20
21
22
# File 'lib/dragonfly/cache/manager.rb', line 18

def initialize(plugin)
  @plugin = plugin
  @map = Dragonfly::Cache::Mapper::Yaml.new(config.servers_options)
  @storage = Dragonfly::Cache::Storage::Local.new(config.servers_options)
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



14
15
16
# File 'lib/dragonfly/cache/manager.rb', line 14

def map
  @map
end

#pluginObject (readonly)

Returns the value of attribute plugin.



14
15
16
# File 'lib/dragonfly/cache/manager.rb', line 14

def plugin
  @plugin
end

#storageObject (readonly)

Returns the value of attribute storage.



14
15
16
# File 'lib/dragonfly/cache/manager.rb', line 14

def storage
  @storage
end

Instance Method Details

#cache(job) ⇒ Object



24
25
26
27
28
# File 'lib/dragonfly/cache/manager.rb', line 24

def cache(job)
  return @map[job.sha] if @map.key?(job.sha)

  store(job, yield)
end

#job_options(job) ⇒ Object



37
38
39
40
41
42
# File 'lib/dragonfly/cache/manager.rb', line 37

def job_options(job)
  {
    shaish: shaish(job),
    normalized_name: normalized_name(job)
  }
end

#valid?(job, uri) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/dragonfly/cache/manager.rb', line 30

def valid?(job, uri)
  valid = (@map.key?(job.sha) && @map[job.sha] == uri) || !@map.key?(job.sha)
  valid &= (@map.value?(uri) && @map.key(uri) == job.sha) || !@map.value?(uri)
  increase_sha_size! unless valid
  valid
end