class Applitools::Selenium::ResourceCache
Attributes
Public Class Methods
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 9 def initialize self.cache_map = {} self.semaphore = Mutex.new end
Public Instance Methods
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 29 def [](key) current_value = semaphore.synchronize do cache_map[key] end raise ResourceMissing, key if current_value.nil? return current_value unless current_value.is_a? Applitools::Future update_cache_map(key, current_value.get) end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 38 def []=(key, value) Applitools::ArgumentGuard.is_a?(key, 'key', URI) Applitools::ArgumentGuard.one_of?(value, 'value', [Applitools::Future, Applitools::Selenium::VGResource]) update_cache_map(key, value) end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 23 def contains?(url) semaphore.synchronize do check_key(url) end end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 44 def fetch_and_store(key, &_block) semaphore.synchronize do return cache_map[key] if check_key(key) return unless block_given? cache_map[key] = Applitools::Future.new(semaphore, "ResourceCache - #{key}") do |semaphore| yield(semaphore, key) end return true if cache_map[key].is_a? Applitools::Future false end end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 14 def keys cache_map.keys end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 18 def urls_to_skip return nil if keys.empty? '"' + keys.map(&:to_s).join('", "') + '"' end
Private Instance Methods
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 58 def check_key(url) cache_map.keys.include?(url) && !cache_map[url].nil? end
Source
# File lib/applitools/selenium/visual_grid/resource_cache.rb, line 62 def update_cache_map(key, value) semaphore.synchronize do cache_map[key] = value end end