class Danger::HTTPCache
Attributes
expires_in[R]
Public Class Methods
new(cache_file = nil, options = {})
click to toggle source
# File lib/danger/commands/local_helpers/http_cache.rb, line 7 def initialize(cache_file = nil, options = {}) File.delete(cache_file) if options[:clear_cache] @store = PStore.new(cache_file) @expires_in = options[:expires_in] || 300 # 5 minutes end
Public Instance Methods
delete(key)
click to toggle source
# File lib/danger/commands/local_helpers/http_cache.rb, line 24 def delete(key) @store.transaction { @store.delete key } end
entry_has_expired(entry, ttl)
click to toggle source
# File lib/danger/commands/local_helpers/http_cache.rb, line 34 def entry_has_expired(entry, ttl) Time.now.to_i > entry[:updated_at].to_i + ttl.to_i end
read(key)
click to toggle source
# File lib/danger/commands/local_helpers/http_cache.rb, line 13 def read(key) @store.transaction do entry = @store[key] return nil unless entry return entry[:value] unless entry_has_expired(entry, @expires_in) @store.delete key return nil end end
write(key, value)
click to toggle source
# File lib/danger/commands/local_helpers/http_cache.rb, line 28 def write(key, value) @store.transaction do @store[key] = { updated_at: Time.now.to_i, value: value } end end