class ActiveFedora::CachingConnection
def cache
def cache old = @cache_enabled @cache_enabled = true yield ensure @cache_enabled = old clear_cache unless @cache_enabled end
def cache_resource(url, &_block)
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
def clear_cache
def clear_cache @cache.clear end
def disable_cache!
def disable_cache! @cache_enabled = false end
def enable_cache!
def enable_cache! @cache_enabled = true end
def get(url, options = {})
def get(url, options = {}) if @cache_enabled cache_resource(url) { super } else super end end
def initialize(host, options = {})
def initialize(host, options = {}) super @cache = {} @cache_enabled = false end
def log(url)
def log(url) ActiveSupport::Notifications.instrument("ldp.active_fedora", id: url, name: "Load LDP", ldp_service: object_id) { yield } end
def patch(*)
def patch(*) clear_cache if @cache_enabled super end
def post(*)
def post(*) clear_cache if @cache_enabled super end
def put(*)
def put(*) clear_cache if @cache_enabled super end
def uncached
def uncached old = @cache_enabled @cache_enabled = false yield ensure @cache_enabled = old end