Module: Merb::ConditionalGetMixin

Module | Merb::ConditionalGetMixin
In: | lib/merb-core/controller/mixins/conditional_get.rb

Provides conditional get support in Merb core. Conditional get support is intentionally simple and does not do fancy stuff like making ETag value from Ruby objects for you.

The most interesting method for end user is +request_fresh?+ that is used after setting of last modification time or ETag:

#### Example

def show

      self.etag = Digest::SHA1.hexdigest(calculate_cache_key(params))

      if request_fresh?
        self.status = 304
        return ''
      else
        @product = Product.get(params[:id])
        display @product
      end

end

### Methods

etag etag= etag_matches? last_modified last_modified= not_modified? request_fresh?

### Public Instance methods

etag()

#### Returns

<String>: | Value of ETag response header or nil if it‘s not set.

:api: public

etag=(tag)

Sets ETag response header by calling to_s on the argument.

#### Parameters

tag<~to_s>: | value of ETag header enclosed in double quotes as required by the RFC

:api: public

etag_matches?(tag = self.etag)

#### Returns

<Boolean>:: true if ETag response header equals If-None-Match request header, false otherwise

:api: public

last_modified()

#### Returns

<String>: | Value of Last-Modified response header or nil if it‘s not set.

:api: public

last_modified=(time)

Sets Last-Modified response header.

#### Parameters

tag<Time>:: resource modification timestamp converted into format required by the RFC

:api: public

not_modified?(time = self.last_modified)

#### Returns

<Boolean>:: true if Last-Modified response header is < than If-Modified-Since request header value, false otherwise.

:api: public

request_fresh?()

#### Returns

<Boolean>:: true if either ETag matches or entity is not modified, so request is fresh; false otherwise

:api: public

[Validate]