Sha256: 2d107f5813cf8c2cf6471185a74fa7e3aa36c1cfd92153751e4bab31242986e6

Contents?: true

Size: 1.06 KB

Versions: 22

Compression:

Stored size: 1.06 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 Exception => 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

22 entries across 22 versions & 1 rubygems

Version Path
active-fedora-9.0.8 lib/active_fedora/ldp_cache.rb
active-fedora-9.5.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.4.3 lib/active_fedora/ldp_cache.rb
active-fedora-9.4.2 lib/active_fedora/ldp_cache.rb
active-fedora-9.4.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.4.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.3.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.2.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.2.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.2.0.rc2 lib/active_fedora/ldp_cache.rb
active-fedora-9.2.0.rc1 lib/active_fedora/ldp_cache.rb
active-fedora-9.1.2 lib/active_fedora/ldp_cache.rb
active-fedora-9.1.1 lib/active_fedora/ldp_cache.rb
active-fedora-9.1.0 lib/active_fedora/ldp_cache.rb
active-fedora-9.1.0.rc1 lib/active_fedora/ldp_cache.rb
active-fedora-9.0.6 lib/active_fedora/ldp_cache.rb
active-fedora-9.0.5 lib/active_fedora/ldp_cache.rb
active-fedora-9.0.4 lib/active_fedora/ldp_cache.rb
active-fedora-9.0.3 lib/active_fedora/ldp_cache.rb
active-fedora-9.0.2 lib/active_fedora/ldp_cache.rb