Module: Uricp::Strategy::CacheCommon

Included in:
CachedGet, PipedCache, PipedCacheConvert, PipedRbdGet, RbdCacheCheck, RbdCacheClone, RbdCachedGet, RbdCachedPut, RbdSnap
Defined in:
lib/uricp/strategy/cache_common.rb

Instance Method Summary collapse

Instance Method Details

#cache_exists?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/uricp/strategy/cache_common.rb', line 48

def cache_exists?
  cache_root && %w[temp cache].all? do |d|
    File.directory?(File.join(cache_root, d))
  end
end

#cache_fileObject



62
63
64
# File 'lib/uricp/strategy/cache_common.rb', line 62

def cache_file
  @cache_file ||= File.join(cache_root, 'cache', cache_name)
end

#cache_nameObject



44
45
46
# File 'lib/uricp/strategy/cache_common.rb', line 44

def cache_name
  options['cache_name']
end

#cache_rootObject



40
41
42
# File 'lib/uricp/strategy/cache_common.rb', line 40

def cache_root
  options['cache']
end

#in_cache?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/uricp/strategy/cache_common.rb', line 36

def in_cache?
  File.readable?(cache_file) || options['dry-cache'] == :rbd
end

#temp_cache_fileObject



54
55
56
# File 'lib/uricp/strategy/cache_common.rb', line 54

def temp_cache_file
  @temp_cache_file ||= File.join(cache_root, 'temp', cache_name)
end

#temp_cache_uriObject



58
59
60
# File 'lib/uricp/strategy/cache_common.rb', line 58

def temp_cache_uri
  URI.join('file:///', temp_cache_file)
end

#validate_cache!Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/uricp/strategy/cache_common.rb', line 5

def validate_cache!
  return if dry_run?

  unless cache_exists?
    raise Uricp::MissingCache,
          "no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory"
  end
  return if cache_name

  raise Uricp::MissingCache,
        'no cache name found'
end

#with_active_cacheObject



18
19
20
21
22
23
24
25
# File 'lib/uricp/strategy/cache_common.rb', line 18

def with_active_cache
  if cache_root
    yield
  else
    debug "#{self.class.name}: no cacheing requested"
    false
  end
end

#without_active_cacheObject



27
28
29
30
31
32
33
34
# File 'lib/uricp/strategy/cache_common.rb', line 27

def without_active_cache
  unless cache_root
    yield
  else
    debug "#{self.class.name}: cache active - not appropriate"
    false
  end
end