Module: BackgroundCache

Defined in:
lib/background_cache.rb,
lib/background_cache/client.rb,
lib/background_cache/config.rb,
lib/background_cache/daemon.rb,
lib/background_cache/helper.rb,
lib/background_cache/mem_cache.rb,
lib/background_cache/controller.rb

Defined Under Namespace

Modules: Controller, Helper, Memcache Classes: AppInstance, Client, Config, Daemon

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/background_cache.rb', line 36

def self.active?
  BackgroundCache::Config.current_cache
end

.cache!(group = nil, instance = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/background_cache.rb', line 40

def self.cache!(group=nil, instance=nil)
  unless instance
    instance = self.boot
  end
  BackgroundCache::Config.load!(group)
  caches = BackgroundCache::Config.caches
  caches.each do |cache|
    next if group && cache[:group] != group
    self.manual(cache, instance)
  end
end

.manual(cache, instance = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/background_cache.rb', line 52

def self.manual(cache, instance=nil)
  ENV['BACKGROUND_CACHE'] = '1'
  unless instance
    instance = self.boot
  end
  BackgroundCache::Config.current_cache = cache
  url = cache[:path] || instance.url_for(cache[:params].merge(:only_path => true))
  puts "(#{cache[:group]}) #{url}"
  instance.get(url)
  BackgroundCache::Config.current_cache = nil
  url
end

.match?(fragment = {}) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/background_cache.rb', line 65

def self.match?(fragment={})
  BackgroundCache::Config.match?(fragment)
end