Class: Cardiac::ResourceCache
- Inherits:
-
Object
- Object
- Cardiac::ResourceCache
- Defined in:
- lib/cardiac/resource/cache.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods Classes: Middleware
Class Method Summary collapse
-
.configured? ⇒ Boolean
Until the load hooks run, we do without a resource cache.
Instance Method Summary collapse
-
#cache ⇒ Object
Enable the resource cache within the block.
- #clear_resource_cache ⇒ Object
-
#configured? ⇒ Boolean
Checks if the resource cache has been initialized.
- #disable_resource_cache! ⇒ Object
- #enable_resource_cache! ⇒ Object
-
#initialize ⇒ ResourceCache
constructor
A new instance of ResourceCache.
-
#resource_cache_enabled?(verb = nil) ⇒ Boolean
Checks if the resource cache is currently enabled and, optionally, if it applies to the given verb.
-
#uncached ⇒ Object
Disable the resource cache within the block.
Constructor Details
#initialize ⇒ ResourceCache
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.
132 133 |
# File 'lib/cardiac/resource/cache.rb', line 132 def self.configured? end |
Instance Method Details
#cache ⇒ Object
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_cache ⇒ Object
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.
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.
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 |
#uncached ⇒ Object
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 |