class ActiveFedora::CachingConnection
Public Class Methods
new(host, options = {})
click to toggle source
Calls superclass method
# File lib/active_fedora/caching_connection.rb, line 3 def initialize(host, options = {}) super @cache = {} @cache_enabled = false end
Public Instance Methods
cache() { || ... }
click to toggle source
Enable the cache within the block.
# 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()
click to toggle source
# File lib/active_fedora/caching_connection.rb, line 59 def clear_cache @cache.clear end
disable_cache!()
click to toggle source
# File lib/active_fedora/caching_connection.rb, line 46 def disable_cache! @cache_enabled = false end
enable_cache!()
click to toggle source
# File lib/active_fedora/caching_connection.rb, line 42 def enable_cache! @cache_enabled = true end
get(url, options = {})
click to toggle source
Calls superclass method
# File lib/active_fedora/caching_connection.rb, line 9 def get(url, options = {}) if @cache_enabled cache_resource(url) { super } else log(url) { super } end end
patch(*)
click to toggle source
Calls superclass method
# File lib/active_fedora/caching_connection.rb, line 27 def patch(*) clear_cache if @cache_enabled super end
post(*)
click to toggle source
Calls superclass method
# File lib/active_fedora/caching_connection.rb, line 17 def post(*) clear_cache if @cache_enabled super end
put(*)
click to toggle source
Calls superclass method
# File lib/active_fedora/caching_connection.rb, line 22 def put(*) clear_cache if @cache_enabled super end
uncached() { || ... }
click to toggle source
Disable the query cache within the block.
# File lib/active_fedora/caching_connection.rb, line 51 def uncached old = @cache_enabled @cache_enabled = false yield ensure @cache_enabled = old end
Private Instance Methods
cache_resource(url) { || ... }
click to toggle source
# File lib/active_fedora/caching_connection.rb, line 70 def cache_resource(url, &_block) result = if @cache.key?(url) ActiveSupport::Notifications.instrument("ldp.active_fedora", id: url, name: "CACHE", ldp_service: object_id) @cache[url] else @cache[url] = log(url) { yield } end result.dup end
log(url) { || ... }
click to toggle source
# File lib/active_fedora/caching_connection.rb, line 65 def log(url) ActiveSupport::Notifications.instrument("ldp.active_fedora", id: url, name: "Load LDP", ldp_service: object_id) { yield } end