Module: Uricp::Strategy::CacheCommon
- Included in:
- CachedGet, PipedCache, PipedCacheConvert
- 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
Instance Method Details
#cache_exists? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/uricp/strategy/cache_common.rb', line 26 def cache_exists? cache_root && %w{temp cache}.all? do |d| File.directory?(File.join(cache_root, d)) end end |
#cache_file ⇒ Object
40 41 42 |
# File 'lib/uricp/strategy/cache_common.rb', line 40 def cache_file @cache_file ||= File.join(cache_root, 'cache', cache_name) end |
#cache_name ⇒ Object
22 23 24 |
# File 'lib/uricp/strategy/cache_common.rb', line 22 def cache_name ['cache_name'] end |
#cache_root ⇒ Object
18 19 20 |
# File 'lib/uricp/strategy/cache_common.rb', line 18 def cache_root ['cache'] end |
#in_cache? ⇒ Boolean
14 15 16 |
# File 'lib/uricp/strategy/cache_common.rb', line 14 def in_cache? File.readable? cache_file end |
#temp_cache_file ⇒ Object
32 33 34 |
# File 'lib/uricp/strategy/cache_common.rb', line 32 def temp_cache_file @temp_cache_file ||= File.join(cache_root, 'temp', cache_name) end |
#temp_cache_uri ⇒ Object
36 37 38 |
# File 'lib/uricp/strategy/cache_common.rb', line 36 def temp_cache_uri URI.join('file:///', temp_cache_file) end |
#validate_cache! ⇒ Object
7 8 9 10 11 12 |
# File 'lib/uricp/strategy/cache_common.rb', line 7 def validate_cache! raise Uricp::MissingCache, "no cache found at #{cache_root}. Expected a 'cache' and 'temp' directory" unless cache_exists? raise Uricp::MissingCache, "no cache name found" unless cache_name end |