Class: ActiveFedora::CachingConnection
- Inherits:
-
Ldp::Client
- Object
- Ldp::Client
- ActiveFedora::CachingConnection
- Defined in:
- lib/active_fedora/caching_connection.rb
Instance Method Summary collapse
-
#cache ⇒ Object
Enable the cache within the block.
- #clear_cache ⇒ Object
- #disable_cache! ⇒ Object
- #enable_cache! ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize(host) ⇒ CachingConnection
constructor
A new instance of CachingConnection.
- #patch ⇒ Object
- #post ⇒ Object
- #put ⇒ Object
-
#uncached ⇒ Object
Disable the query cache within the block.
Constructor Details
#initialize(host) ⇒ CachingConnection
Returns a new instance of CachingConnection.
3 4 5 6 7 |
# File 'lib/active_fedora/caching_connection.rb', line 3 def initialize(host) super @cache = {} @cache_enabled = false end |
Instance Method Details
#cache ⇒ Object
Enable the cache within the block.
33 34 35 36 37 38 39 |
# File 'lib/active_fedora/caching_connection.rb', line 33 def cache old, @cache_enabled = @cache_enabled, true yield ensure @cache_enabled = old clear_cache unless @cache_enabled end |
#clear_cache ⇒ Object
57 58 59 |
# File 'lib/active_fedora/caching_connection.rb', line 57 def clear_cache @cache.clear end |
#disable_cache! ⇒ Object
45 46 47 |
# File 'lib/active_fedora/caching_connection.rb', line 45 def disable_cache! @cache_enabled = false end |
#enable_cache! ⇒ Object
41 42 43 |
# File 'lib/active_fedora/caching_connection.rb', line 41 def enable_cache! @cache_enabled = true end |
#get(url, options = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_fedora/caching_connection.rb', line 9 def get(url, = {}) if @cache_enabled cache_resource(url) { super } else super end end |
#patch ⇒ Object
27 28 29 30 |
# File 'lib/active_fedora/caching_connection.rb', line 27 def patch(*) clear_cache if @cache_enabled super end |
#post ⇒ Object
17 18 19 20 |
# File 'lib/active_fedora/caching_connection.rb', line 17 def post(*) clear_cache if @cache_enabled super end |
#put ⇒ Object
22 23 24 25 |
# File 'lib/active_fedora/caching_connection.rb', line 22 def put(*) clear_cache if @cache_enabled super end |
#uncached ⇒ Object
Disable the query cache within the block.
50 51 52 53 54 55 |
# File 'lib/active_fedora/caching_connection.rb', line 50 def uncached old, @cache_enabled = @cache_enabled, false yield ensure @cache_enabled = old end |