Class: Cardiac::ResourceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/cardiac/resource/cache.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: Middleware

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResourceCache

Returns a new instance of ResourceCache.



121
122
123
124
# File 'lib/cardiac/resource/cache.rb', line 121

def initialize
  @resource_cache         = Hash.new { |h,url| h[url] = {} }
  @resource_cache_enabled = false
end

Class Method Details

.configured?Boolean

Until the load hooks run, we do without a resource cache.

Returns:

  • (Boolean)


132
133
# File 'lib/cardiac/resource/cache.rb', line 132

def self.configured?
end

Instance Method Details

#cacheObject

Enable the resource cache within the block.



12
13
14
15
16
17
18
# File 'lib/cardiac/resource/cache.rb', line 12

def cache
  old, @resource_cache_enabled = @resource_cache_enabled, true
  yield
ensure
  clear_resource_cache
  @resource_cache_enabled = old
end

#clear_resource_cacheObject



36
37
38
# File 'lib/cardiac/resource/cache.rb', line 36

def clear_resource_cache
  @resource_cache.clear
end

#configured?Boolean

Checks if the resource cache has been initialized.

Returns:

  • (Boolean)


127
128
129
# File 'lib/cardiac/resource/cache.rb', line 127

def configured?
  ! @resource_cache.nil?
end

#disable_resource_cache!Object



24
25
26
# File 'lib/cardiac/resource/cache.rb', line 24

def disable_resource_cache!
  @resource_cache_enabled = false
end

#enable_resource_cache!Object



20
21
22
# File 'lib/cardiac/resource/cache.rb', line 20

def enable_resource_cache!
  @resource_cache_enabled = true
end

#resource_cache_enabled?(verb = nil) ⇒ Boolean

Checks if the resource cache is currently enabled and, optionally, if it applies to the given verb.

Returns:

  • (Boolean)


7
8
9
# File 'lib/cardiac/resource/cache.rb', line 7

def resource_cache_enabled?(verb=nil)
  @resource_cache_enabled && case verb when NilClass, 'GET', 'HEAD' then true end
end

#uncachedObject

Disable the resource cache within the block.



29
30
31
32
33
34
# File 'lib/cardiac/resource/cache.rb', line 29

def uncached
  old, @resource_cache_enabled = @resource_cache_enabled, false
  yield
ensure
  @resource_cache_enabled = old
end