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
- #cache_exists? ⇒ Boolean
- #cache_file ⇒ Object
- #cache_name ⇒ Object
- #cache_root ⇒ Object
- #in_cache? ⇒ Boolean
- #temp_cache_file ⇒ Object
- #temp_cache_uri ⇒ Object
- #validate_cache! ⇒ Object
- #with_active_cache ⇒ Object
- #without_active_cache ⇒ Object
Instance Method Details
#cache_exists? ⇒ Boolean
50 51 52 53 54 |
# File 'lib/uricp/strategy/cache_common.rb', line 50 def cache_exists? cache_root && %w[temp cache].all? do |d| File.directory?(File.join(cache_root, d)) end end |
#cache_file ⇒ Object
64 65 66 |
# File 'lib/uricp/strategy/cache_common.rb', line 64 def cache_file @cache_file ||= File.join(cache_root, 'cache', cache_name) end |
#cache_name ⇒ Object
46 47 48 |
# File 'lib/uricp/strategy/cache_common.rb', line 46 def cache_name ['cache_name'] end |
#cache_root ⇒ Object
42 43 44 |
# File 'lib/uricp/strategy/cache_common.rb', line 42 def cache_root ['cache'] end |
#in_cache? ⇒ Boolean
38 39 40 |
# File 'lib/uricp/strategy/cache_common.rb', line 38 def in_cache? File.readable?(cache_file) || ['dry-cache'] == :rbd end |
#temp_cache_file ⇒ Object
56 57 58 |
# File 'lib/uricp/strategy/cache_common.rb', line 56 def temp_cache_file @temp_cache_file ||= File.join(cache_root, 'temp', cache_name) end |
#temp_cache_uri ⇒ Object
60 61 62 |
# File 'lib/uricp/strategy/cache_common.rb', line 60 def temp_cache_uri URI.join('file:///', temp_cache_file) end |
#validate_cache! ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/uricp/strategy/cache_common.rb', line 7 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_cache ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/uricp/strategy/cache_common.rb', line 20 def with_active_cache if cache_root yield else debug "#{self.class.name}: no cacheing requested" false end end |
#without_active_cache ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/uricp/strategy/cache_common.rb', line 29 def without_active_cache if cache_root debug "#{self.class.name}: cache active - not appropriate" false else yield end end |