Sha256: 15c6a1700330d81498567c677537484d565038a8a9e6d8fe041db55eb9b149c8

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

module ActiveFedora
  # = Active Fedora Ldp Cache
  class LdpCache
    module ClassMethods
      # Enable the query cache within the block if Active Fedora is configured.
      # If it's not, it will execute the given block.
      def cache(&block)
        connection = ActiveFedora.fedora.connection
        connection.cache(&block)
      end

      # Disable the query cache within the block if Active Fedora is configured.
      # If it's not, it will execute the given block.
      def uncached(&block)
        ActiveFedora.fedora.connection.uncached(&block)
      end
    end

    def initialize(app)
      @app = app
    end

    def call(env)
      ActiveFedora.fedora.connection.enable_cache!

      response = @app.call(env)
      response[2] = Rack::BodyProxy.new(response[2]) do
        reset_cache_settings
      end

      response
    rescue StandardError => e
      reset_cache_settings
      raise e
    end

    private

      def reset_cache_settings
        ActiveFedora.fedora.connection.clear_cache
        ActiveFedora.fedora.connection.disable_cache!
      end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/ldp_cache.rb
active-fedora-9.7.2 lib/active_fedora/ldp_cache.rb
active-fedora-9.12.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.11.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.4 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.3 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.2 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.0.pre2 lib/active_fedora/ldp_cache.rb
active-fedora-9.10.0.pre1 lib/active_fedora/ldp_cache.rb
active-fedora-9.9.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.9.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.8.2 lib/active_fedora/ldp_cache.rb
active-fedora-9.8.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.8.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.7.1 lib/active_fedora/ldp_cache.rb