Sha256: 92fb99b88845d79cc8440d6deb7d48a821c7066eadfd8a8514c3be0645009772
Contents?: true
Size: 952 Bytes
Versions: 1
Compression:
Stored size: 952 Bytes
Contents
# -*- encoding: binary -*- # helpers for domain lookups module Regurgitator::Domain # :nodoc: REFRESH_DOMAIN = 'SELECT dmid,namespace FROM domain' # :nodoc: def domain_init @domain_lock = Mutex.new @domain_cache_mtime = Time.at(0) @domain_cache = nil end # returns the +dmid+ (domain identifier/primary key) for a string +domain+ def get_dmid(domain) refresh_domain[domain] || false end # We cache the list of all available domains in memory, this shouldn't # be too huge, though... # # Returns a hash with string namespaces as keys and dmids as values def refresh_domain # :nodoc: @domain_lock.synchronize { refresh_domain_unlocked } end def refresh_domain_unlocked # :nodoc: return @domain_cache if ((Time.now - @domain_cache_mtime) < 15) tmp = {} @db[REFRESH_DOMAIN].each { |x| tmp[x[:namespace].freeze] = x[:dmid] } @domain_cache_mtime = Time.now @domain_cache = tmp end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
regurgitator-0.7.0 | lib/regurgitator/domain.rb |