Interface nsICachingChannelType

A channel may optionally implement this interface to allow clients to affect its behavior with respect to how it uses the cache service.

This interface provides:

  1. Support for "stream as file" semantics (for JAR and plugins).
  2. Support for "pinning" cached data in the cache (for printing and save-as).
  3. Support for uniquely identifying cached data in cases when the URL is insufficient (e.g., HTTP form submission).

Hierarchy

Properties

allowStaleCacheContent: boolean

Tells the channel to behave as if the LOAD_FROM_CACHE flag has been set, but without affecting the loads for the entire loadGroup in case of this channel being the default load group's channel.

alternativeDataInputStream: nsIInputStream

If preferAlternativeDataType() has been called passing deliverAltData equal to false, this attribute will expose the alt-data inputStream if avaiable.

alternativeDataType: string

Holds the type of the alternative data representation that the channel is returning. Is empty string if no alternative data representation was requested, or if the requested representation wasn't found in the cache. Can only be called during or after OnStartRequest.

cacheKey: number

Set/get the cache key. This integer uniquely identifies the data in the cache for this channel.

A cache key retrieved from a particular instance of nsICacheInfoChannel could be set on another instance of nsICacheInfoChannel provided the underlying implementations are compatible and provided the new channel instance was created with the same URI. The implementation of nsICacheInfoChannel would be expected to use the cache entry identified by the cache token. Depending on the value of nsIRequest::loadFlags, the cache entry may be validated, overwritten, or simply read.

The cache key may be 0 indicating that the URI of the channel is sufficient to locate the same cache entry. Setting a 0 cache key is likewise valid.

cacheOnlyMetadata: boolean

Instructs the channel to only store the metadata of the entry, and not the content. When reading an existing entry, this automatically sets LOAD_ONLY_IF_MODIFIED flag. Must be called before asyncOpen().

cacheToken: nsISupports

Set/get the cache token... uniquely identifies the data in the cache. Holding a reference to this token prevents the cached data from being removed.

A cache token retrieved from a particular instance of nsICachingChannel could be set on another instance of nsICachingChannel provided the underlying implementations are compatible. The implementation of nsICachingChannel would be expected to only read from the cache entry identified by the cache token and not try to validate it.

The cache token can be QI'd to a nsICacheEntryInfo if more detail about the cache entry is needed (e.g., expiration time).

cacheTokenExpirationTime: uint32_t

Get expiration time from cache token. This attribute is equivalent to nsICachingChannel.cacheToken.expirationTime.

cacheTokenFetchCount: uint32_t

Get the number of times the cache entry has been opened. This attribute is equivalent to nsICachingChannel.cacheToken.fetchCount.

Throws

NS_ERROR_NOT_AVAILABLE if the cache entry or the alternate data cache entry cannot be read.

forceValidateCacheContent: boolean

Tells the channel to be force validated during soft reload.

pin: boolean

Tells the channel to use the pinning storage.

preferCacheLoadOverBypass: boolean

Tells the priority for LOAD_CACHE is raised over LOAD_BYPASS_CACHE or LOAD_BYPASS_LOCAL_CACHE in case those flags are set at the same time.

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • Overrides cache validation for a time specified in seconds.

    Parameters

    • aSecondsToTheFuture: number

    Returns void

  • The unique ID of the corresponding nsICacheEntry from which the response is retrieved. By comparing the returned value, we can judge whether the data of two distinct nsICacheInfoChannels is from the same nsICacheEntry. This scenario could be useful when verifying whether the alternative data from one nsICacheInfochannel matches the main data from another one.

    Note: NS_ERROR_NOT_AVAILABLE is thrown when a nsICacheInfoChannel has no valid corresponding nsICacheEntry.

    Returns uint64_t

  • Sometimes when the channel is delivering alt-data, we may want to somehow access the original content too. This method asynchronously opens the input stream and delivers it to the receiver.

    Parameters

    • aReceiver: nsIInputStreamReceiver

    Returns void

  • TRUE if this channel's data is being loaded from the cache. This value is undefined before the channel fires its OnStartRequest notification and after the channel fires its OnStopRequest notification.

    Returns boolean

  • Returns true if the channel raced the cache and network requests. In order to determine if the response is coming from the cache or the network, the consumer can check isFromCache(). The method can only be called after the channel fires its OnStartRequest notification.

    Returns boolean

  • Opens and returns an output stream that a consumer may use to save an alternate representation of the data. Must be called after the OnStopRequest that delivered the real data. The consumer may choose to replace the saved alt representation. Opening the output stream will fail if there are any open input streams reading the already saved alt representation. After successfully opening an output stream, if there is an error before the entire alt data can be written successfully, the client must signal failure by passing an error code to CloseWithStatus().

    Parameters

    • type: string

      type of the alternative data representation

    • predictedSize: number

      Predicted size of the data that will be written. It's used to decide whether the resulting entry would exceed size limit, in which case an error is thrown. If the size isn't known in advance, -1 should be passed.

    Returns nsIAsyncOutputStream

  • Calling this method instructs the channel to serve the alternative data if that was previously saved in the cache, otherwise it will serve the real data.

    Parameters

    • type: string

      a string identifying the alt-data format

    • contentType: string

      the contentType for which the preference applies. an empty contentType means the preference applies for ANY contentType

    • deliverAltData: nsICacheInfoChannel_PreferredAlternativeDataDeliveryType

      if false, also if alt-data is available, the channel will deliver the original data.

      The method may be called several times, with different type and contentType.

      Must be called before AsyncOpen.

    Returns void

  • Get the preferred alternative data type set by preferAlternativeDataType(). The returned types stand for the desired data type instead of the type of the information retrieved from the network stack.

    Returns ConstPreferredAlternativeDataTypeArray

Generated using TypeDoc