Sha256: bc07808116290b8c8fa20c056f1640402faae244f5e57ed365b226643a587a07

Contents?: true

Size: 1.04 KB

Versions: 67

Compression:

Stored size: 1.04 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
    ensure
      reset_cache_settings
    end

    private

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

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
active-fedora-11.1.4 lib/active_fedora/ldp_cache.rb
active-fedora-11.1.3 lib/active_fedora/ldp_cache.rb
active-fedora-11.1.2 lib/active_fedora/ldp_cache.rb
active-fedora-11.1.1 lib/active_fedora/ldp_cache.rb
active-fedora-11.1.0 lib/active_fedora/ldp_cache.rb
active-fedora-10.3.0 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.1 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0 lib/active_fedora/ldp_cache.rb
active-fedora-10.3.0.rc2 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc7 lib/active_fedora/ldp_cache.rb
active-fedora-10.3.0.rc1 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc6 lib/active_fedora/ldp_cache.rb
active-fedora-10.2.1 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc5 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc4 lib/active_fedora/ldp_cache.rb
active-fedora-10.2.0 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc3 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc2 lib/active_fedora/ldp_cache.rb
active-fedora-11.0.0.rc1 lib/active_fedora/ldp_cache.rb
active-fedora-10.1.0 lib/active_fedora/ldp_cache.rb