class Apollo::Cache::MemoryCache

Public Class Methods

new(options = {}) click to toggle source
# File lib/apollo_crawler/cache/memory_cache.rb, line 28
def initialize(options = {})
        @cache = {}
end

Public Instance Methods

get(key) click to toggle source
# File lib/apollo_crawler/cache/memory_cache.rb, line 32
def get(key)
        @cache[key]
end
set(key, value) click to toggle source

Set value associated with key Return cached value

# File lib/apollo_crawler/cache/memory_cache.rb, line 50
def set(key, value)
        @cache[key] = value
end
try_get(key, *args) { |args| ... } click to toggle source

Get value associated with key from cache

# File lib/apollo_crawler/cache/memory_cache.rb, line 37
def try_get(key, *args)
        res = get(key)

        # Not found, Create, cache and return
        if res.nil? && block_given?
                res = yield args
        end
        
        return res
end