Section 16. Caching

In HTTP, request/response pairs are cached.  RTSP differs
   significantly in that respect.  Responses are not cacheable, with the
   exception of the presentation description returned by DESCRIBE.
   (Since the responses for anything but DESCRIBE and GET_PARAMETER do
   not return any data, caching is not really an issue for these
   requests.)  However, it is desirable for the continuous media data,
   typically delivered out-of-band with respect to RTSP, to be cached,
   as well as the session description.
   On receiving a SETUP or PLAY request, a proxy ascertains whether it
   has an up-to-date copy of the continuous media content and its
   description.  It can determine whether the copy is up to date by
   issuing a SETUP or DESCRIBE request, respectively, and comparing the
   Last-Modified header with that of the cached copy.  If the copy is
   not up to date, it modifies the SETUP transport parameters as
   appropriate and forwards the request to the origin server.
   Subsequent control commands such as PLAY or PAUSE then pass the proxy
   unmodified.  The proxy delivers the continuous media data to the
   client, while possibly making a local copy for later reuse.  The
   exact allowed behavior of the cache is given by the cache-response
   directives described in Section 18.11.  A cache MUST answer any
   DESCRIBE requests if it is currently serving the stream to the
   requester, as it is possible that low-level details of the stream
   description may have changed on the origin server.
   Note that an RTSP cache is of the "cut-through" variety.  Rather than
   retrieving the whole resource from the origin server, the cache
   simply copies the streaming data as it passes by on its way to the
   client.  Thus, it does not introduce additional latency.
   To the client, an RTSP proxy cache appears like a regular media
   server.  To the media origin server, an RTSP proxy cache appears like
   a client.  Just as an HTTP cache has to store the content type,
   content language, and so on for the objects it caches, a media cache
   has to store the presentation description.  Typically, a cache
   eliminates all transport references (e.g., multicast information)
   from the presentation description, since these are independent of the
   data delivery from the cache to the client.  Information on the
   encodings remains the same.  If the cache is able to translate the
   cached media data, it would create a new presentation description
   with all the encoding possibilities it can offer.
16.1.  Validation Model
   When a cache has a stale entry that it would like to use as a
   response to a client's request, it first has to check with the origin
   server (or possibly an intermediate cache with a fresh response) to
   see if its cached entry is still usable.  This is called "validating"
   the cache entry.  To avoid having to pay the overhead of
   retransmitting the full response if the cached entry is good, and at
   the same time avoiding having to pay the overhead of an extra round
   trip if the cached entry is invalid, RTSP supports the use of
   conditional methods.
   The key protocol features for supporting conditional methods are
   those concerned with "cache validators."  When an origin server
   generates a full response, it attaches some sort of validator to it,
   which is kept with the cache entry.  When a client (user agent or
   proxy cache) makes a conditional request for a resource for which it
   has a cache entry, it includes the associated validator in the
   request.
   The server then checks that validator against the current validator
   for the requested resource, and, if they match (see Section 16.1.3),
   it responds with a special status code (usually, 304 (Not Modified))
   and no message body.  Otherwise, it returns a full response
   (including message body).  Thus, avoiding transmitting the full
   response if the validator matches and avoiding an extra round trip if
   it does not match.
   In RTSP, a conditional request looks exactly the same as a normal
   request for the same resource, except that it carries a special
   header (which includes the validator) that implicitly turns the
   method (usually DESCRIBE or SETUP) into a conditional.
   The protocol includes both positive and negative senses of cache-
   validating conditions.  That is, it is possible to request that a
   method be performed either if and only if a validator matches or if
   and only if no validators match.
      Note: a response that lacks a validator may still be cached, and
      served from cache until it expires, unless this is explicitly
      prohibited by a cache directive (see Section 18.11).  However, a
      cache cannot perform a conditional retrieval if it does not have a
      validator for the resource, which means it will not be refreshable
      after it expires.
   Media streams that are being adapted based on the transport capacity
   between the server and the cache make caching more difficult.  A
   server needs to consider how it views the caching of media streams
   that it adapts and potentially instruct any caches not to cache such
   streams.
16.1.1.  Last-Modified Dates
   The Last-Modified header (Section 18.27) value is often used as a
   cache validator.  In simple terms, a cache entry is considered to be
   valid if the cache entry was created after the Last-Modified time.
16.1.2.  Message Body Tag Cache Validators
   The MTag response-header field-value, a message body tag, provides
   for an "opaque" cache validator.  This might allow more reliable
   validation in situations where it is inconvenient to store
   modification dates, where the one-second resolution of RTSP-date
   values is not sufficient, or where the origin server wishes to avoid
   certain paradoxes that might arise from the use of modification
   dates.
   Message body tags are described in Section 4.6
16.1.3.  Weak and Strong Validators
   Since both origin servers and caches will compare two validators to
   decide if they represent the same or different entities, one normally
   would expect that if the message body (i.e., the presentation
   description) or any associated message body headers changes in any
   way, then the associated validator would change as well.  If this is
   true, then this validator is a "strong validator".  The Message body
   (i.e., the presentation description) or any associated message body
   headers is named an entity for a better understanding.
   However, there might be cases when a server prefers to change the
   validator only on semantically significant changes and not when
   insignificant aspects of the entity change.  A validator that does
   not always change when the resource changes is a "weak validator".
   Message body tags are normally strong validators, but the protocol
   provides a mechanism to tag a message body tag as "weak".  One can
   think of a strong validator as one that changes whenever the bits of
   an entity changes, while a weak value changes whenever the meaning of
   an entity changes.  Alternatively, one can think of a strong
   validator as part of an identifier for a specific entity, while a
   weak validator is part of an identifier for a set of semantically
   equivalent entities.
      Note: One example of a strong validator is an integer that is
      incremented in stable storage every time an entity is changed.
      An entity's modification time, if represented with one-second
      resolution, could be a weak validator, since it is possible that
      the resource might be modified twice during a single second.
      Support for weak validators is optional.  However, weak validators
      allow for more efficient caching of equivalent objects.
   A "use" of a validator is either when a client generates a request
   and includes the validator in a validating header field or when a
   server compares two validators.
   Strong validators are usable in any context.  Weak validators are
   only usable in contexts that do not depend on exact equality of an
   entity.  For example, either kind is usable for a conditional
   DESCRIBE of a full entity.  However, only a strong validator is
   usable for a subrange retrieval, since otherwise the client might end
   up with an internally inconsistent entity.
   Clients MAY issue DESCRIBE requests with either weak or strong
   validators.  Clients MUST NOT use weak validators in other forms of
   requests.
   The only function that RTSP defines on validators is comparison.
   There are two validator comparison functions, depending on whether or
   not the comparison context allows the use of weak validators:
   o  The strong comparison function: in order to be considered equal,
      both validators MUST be identical in every way, and both MUST NOT
      be weak.
   o  The weak comparison function: in order to be considered equal,
      both validators MUST be identical in every way, but either or both
      of them MAY be tagged as "weak" without affecting the result.
   A message body tag is strong unless it is explicitly tagged as weak.
   A Last-Modified time, when used as a validator in a request, is
   implicitly weak unless it is possible to deduce that it is strong,
   using the following rules:
   o  The validator is being compared by an origin server to the actual
      current validator for the entity and,
   o  That origin server reliably knows that the associated entity did
      not change more than once during the second covered by the
      presented validator.
   OR
   o  The validator is about to be used by a client in an If-Modified-
      Since, because the client has a cache entry for the associated
      entity, and
   o  That cache entry includes a Date value, which gives the time when
      the origin server sent the original response, and
   o  The presented Last-Modified time is at least 60 seconds before the
      Date value.
   OR
   o  The validator is being compared by an intermediate cache to the
      validator stored in its cache entry for the entity, and
   o  That cache entry includes a Date value, which gives the time when
      the origin server sent the original response, and
   o  The presented Last-Modified time is at least 60 seconds before the
      Date value.
   This method relies on the fact that if two different responses were
   sent by the origin server during the same second, but both had the
   same Last-Modified time, then at least one of those responses would
   have a Date value equal to its Last-Modified time.  The arbitrary
   60-second limit guards against the possibility that the Date and
   Last-Modified values are generated from different clocks or at
   somewhat different times during the preparation of the response.  An
   implementation MAY use a value larger than 60 seconds, if it is
   believed that 60 seconds is too short.
   If a client wishes to perform a subrange retrieval on a value for
   which it has only a Last-Modified time and no opaque validator, it
   MAY do this only if the Last-Modified time is strong in the sense
   described here.
16.1.4.  Rules for When to Use Message Body Tags and Last-Modified Dates
   This document adopts a set of rules and recommendations for origin
   servers, clients, and caches regarding when various validator types
   ought to be used, and for what purposes.
   RTSP origin servers:
   o  SHOULD send a message body tag validator unless it is not feasible
      to generate one.
   o  MAY send a weak message body tag instead of a strong message body
      tag, if performance considerations support the use of weak message
      body tags, or if it is unfeasible to send a strong message body
      tag.
   o  SHOULD send a Last-Modified value if it is feasible to send one,
      unless the risk of a breakdown in semantic transparency that could
      result from using this date in an If-Modified-Since header would
      lead to serious problems.
   In other words, the preferred behavior for an RTSP origin server is
   to send both a strong message body tag and a Last-Modified value.
   In order to be legal, a strong message body tag MUST change whenever
   the associated entity value changes in any way.  A weak message body
   tag SHOULD change whenever the associated entity changes in a
   semantically significant way.
      Note: in order to provide semantically transparent caching, an
      origin server MUST avoid reusing a specific strong message body
      tag value for two different entities or reusing a specific weak
      message body tag value for two semantically different entities.
      Cache entries might persist for arbitrarily long periods,
      regardless of expiration times, so it might be inappropriate to
      expect that a cache will never again attempt to validate an entry
      using a validator that it obtained at some point in the past.
   RTSP clients:
   o  If a message body tag has been provided by the origin server, MUST
      use that message body tag in any cache-conditional request (using
      If-Match or If-None-Match).
   o  If only a Last-Modified value has been provided by the origin
      server, SHOULD use that value in non-subrange cache-conditional
      requests (using If-Modified-Since).
   o  If both a message body tag and a Last-Modified value have been
      provided by the origin server, SHOULD use both validators in
      cache-conditional requests.
   An RTSP origin server, upon receiving a conditional request that
   includes both a Last-Modified date (e.g., in an If-Modified-Since
   header) and one or more message body tags (e.g., in an If-Match,
   If-None-Match, or If-Range header field) as cache validators, MUST
   NOT return a response status of 304 (Not Modified) unless doing so is
   consistent with all of the conditional header fields in the request.
      Note: The general principle behind these rules is that RTSP
      servers and clients should transmit as much non-redundant
      information as is available in their responses and requests.  RTSP
      systems receiving this information will make the most conservative
      assumptions about the validators they receive.
16.1.5.  Non-validating Conditionals
   The principle behind message body tags is that only the service
   author knows the semantics of a resource well enough to select an
   appropriate cache validation mechanism, and the specification of any
   validator comparison function more complex than octet equality would
   open up a can of worms.  Thus, comparisons of any other headers are
   never used for purposes of validating a cache entry.
16.2.  Invalidation after Updates or Deletions
   The effect of certain methods performed on a resource at the origin
   server might cause one or more existing cache entries to become non-
   transparently invalid.  That is, although they might continue to be
   "fresh," they do not accurately reflect what the origin server would
   return for a new request on that resource.
   There is no way for RTSP to guarantee that all such cache entries are
   marked invalid.  For example, the request that caused the change at
   the origin server might not have gone through the proxy where a cache
   entry is stored.  However, several rules help reduce the likelihood
   of erroneous behavior.
   In this section, the phrase "invalidate an entity" means that the
   cache will either remove all instances of that entity from its
   storage or mark these as "invalid" and in need of a mandatory
   revalidation before they can be returned in response to a subsequent
   request.
   Some RTSP methods MUST cause a cache to invalidate an entity.  This
   is either the entity referred to by the Request-URI or by the
   Location or Content-Location headers (if present).  These methods
   are:
   o  DESCRIBE
   o  SETUP
   In order to prevent DoS attacks, an invalidation based on the URI in
   a Location or Content-Location header MUST only be performed if the
   host part is the same as in the Request-URI.
   A cache that passes through requests for methods it does not
   understand SHOULD invalidate any entities referred to by the Request-
   URI.