Module: WebCache::CacheOperations
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
- #dir ⇒ Object
-
#last_error ⇒ Object
readonly
Returns the value of attribute last_error.
-
#pass ⇒ Object
readonly
Returns the value of attribute pass.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #cached?(url) ⇒ Boolean
- #clear(url) ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #enabled? ⇒ Boolean
- #flush ⇒ Object
- #get(url, force: false) ⇒ Object
- #initialize(dir: 'cache', life: '1h', auth: nil) ⇒ Object
- #life ⇒ Object
- #life=(new_life) ⇒ Object
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
7 8 9 |
# File 'lib/webcache/cache_operations.rb', line 7 def auth @auth end |
#dir ⇒ Object
34 35 36 |
# File 'lib/webcache/cache_operations.rb', line 34 def dir @dir ||= 'cache' end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
7 8 9 |
# File 'lib/webcache/cache_operations.rb', line 7 def last_error @last_error end |
#pass ⇒ Object (readonly)
Returns the value of attribute pass.
7 8 9 |
# File 'lib/webcache/cache_operations.rb', line 7 def pass @pass end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/webcache/cache_operations.rb', line 7 def user @user end |
Instance Method Details
#cached?(url) ⇒ Boolean
38 39 40 41 |
# File 'lib/webcache/cache_operations.rb', line 38 def cached?(url) path = get_path url File.exist?(path) and !stale?(path) end |
#clear(url) ⇒ Object
55 56 57 58 |
# File 'lib/webcache/cache_operations.rb', line 55 def clear(url) path = get_path url FileUtils.rm path if File.exist? path end |
#disable ⇒ Object
51 52 53 |
# File 'lib/webcache/cache_operations.rb', line 51 def disable @enabled = false end |
#enable ⇒ Object
47 48 49 |
# File 'lib/webcache/cache_operations.rb', line 47 def enable @enabled = true end |
#enabled? ⇒ Boolean
43 44 45 |
# File 'lib/webcache/cache_operations.rb', line 43 def enabled? @enabled ||= (@enabled.nil? ? true : @enabled) end |
#flush ⇒ Object
60 61 62 |
# File 'lib/webcache/cache_operations.rb', line 60 def flush FileUtils.rm_rf dir if Dir.exist? dir end |
#get(url, force: false) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/webcache/cache_operations.rb', line 17 def get(url, force: false) return http_get url unless enabled? path = get_path url clear url if force or stale? path get! path, url end |
#initialize(dir: 'cache', life: '1h', auth: nil) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/webcache/cache_operations.rb', line 10 def initialize(dir: 'cache', life: '1h', auth: nil) @dir = dir @life = life_to_seconds life @enabled = true @auth = convert_auth auth end |
#life ⇒ Object
26 27 28 |
# File 'lib/webcache/cache_operations.rb', line 26 def life @life ||= 3600 end |
#life=(new_life) ⇒ Object
30 31 32 |
# File 'lib/webcache/cache_operations.rb', line 30 def life=(new_life) @life = life_to_seconds new_life end |