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.
-
#permissions ⇒ Object
Returns the value of attribute permissions.
-
#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, permissions: nil) ⇒ Object
- #life ⇒ Object
- #life=(new_life) ⇒ Object
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
8 9 10 |
# File 'lib/webcache/cache_operations.rb', line 8 def auth @auth end |
#dir ⇒ Object
36 37 38 |
# File 'lib/webcache/cache_operations.rb', line 36 def dir @dir ||= 'cache' end |
#last_error ⇒ Object (readonly)
Returns the value of attribute last_error.
8 9 10 |
# File 'lib/webcache/cache_operations.rb', line 8 def last_error @last_error end |
#pass ⇒ Object (readonly)
Returns the value of attribute pass.
8 9 10 |
# File 'lib/webcache/cache_operations.rb', line 8 def pass @pass end |
#permissions ⇒ Object
Returns the value of attribute permissions.
7 8 9 |
# File 'lib/webcache/cache_operations.rb', line 7 def @permissions end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/webcache/cache_operations.rb', line 8 def user @user end |
Instance Method Details
#cached?(url) ⇒ Boolean
40 41 42 43 |
# File 'lib/webcache/cache_operations.rb', line 40 def cached?(url) path = get_path url File.exist?(path) and !stale?(path) end |
#clear(url) ⇒ Object
57 58 59 60 |
# File 'lib/webcache/cache_operations.rb', line 57 def clear(url) path = get_path url FileUtils.rm path if File.exist? path end |
#disable ⇒ Object
53 54 55 |
# File 'lib/webcache/cache_operations.rb', line 53 def disable @enabled = false end |
#enable ⇒ Object
49 50 51 |
# File 'lib/webcache/cache_operations.rb', line 49 def enable @enabled = true end |
#enabled? ⇒ Boolean
45 46 47 |
# File 'lib/webcache/cache_operations.rb', line 45 def enabled? @enabled ||= (@enabled.nil? ? true : @enabled) end |
#flush ⇒ Object
62 63 64 |
# File 'lib/webcache/cache_operations.rb', line 62 def flush FileUtils.rm_rf dir if Dir.exist? dir end |
#get(url, force: false) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/webcache/cache_operations.rb', line 19 def get(url, force: false) return http_get url unless enabled? path = get_path url clear url if force || stale?(path) get! path, url end |
#initialize(dir: 'cache', life: '1h', auth: nil, permissions: nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/webcache/cache_operations.rb', line 11 def initialize(dir: 'cache', life: '1h', auth: nil, permissions: nil) @dir = dir @life = life_to_seconds life @enabled = true @auth = convert_auth auth @permissions = end |
#life ⇒ Object
28 29 30 |
# File 'lib/webcache/cache_operations.rb', line 28 def life @life ||= 3600 end |
#life=(new_life) ⇒ Object
32 33 34 |
# File 'lib/webcache/cache_operations.rb', line 32 def life=(new_life) @life = life_to_seconds new_life end |