class Apollo::Cache::MemcachedCache

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method Apollo::Cache::BaseCache::new
# File lib/apollo_crawler/cache/memcached_cache.rb, line 29
def initialize(options = {})
        super(options)
        
        @cache = Dalli::Client.new()
end

Public Instance Methods

get(key) click to toggle source
# File lib/apollo_crawler/cache/memcached_cache.rb, line 35
def get(key)
        @cache.get(key)
end
set(key, value) click to toggle source

Set value associated with key Return cached value

# File lib/apollo_crawler/cache/memcached_cache.rb, line 55
def set(key, value)
        @cache.set(key, value)
        return key
end
try_get(key, *args) { |args| ... } click to toggle source

Get value associated with key from cache

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

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

                self.set(key, res)
        end
        
        return res
end