Home

Traffic Server Software Developers Kit

INKCacheRead

Initiates a cache read or lookup of an object in the Traffic Server cache.

Prototype

INKAction INKCacheRead (INKCont contp, INKCacheKey key)

Arguments

INKCont contp is the continuation the cache calls back (telling it whether the object exists and can be read).

INKCacheKey key is the cache key corresponding to the object to be read.

Description

Asks the Traffic Server cache if the object corresponding to key exists in the cache and can be read.

You can do a cache lookup to determine whether or not an object is in the cache. To do a cache lookup, call INKCacheRead on a continuation contp. If the object can be read, then the cache calls contp back with the event INK_EVENT_CACHE_OPEN_READ. In this case, the cache also passes contp a cache vconnection; contp can then initiate a read operation on that vconnection using INKVConnRead. INKVConnCacheObjectSizeGet can be used to determine the size of the object in the cache.

If the object cannot be read (if, for instance, it is not in the cache), then the cache calls contp back with the event INK_EVENT_CACHE_OPEN_READ_FAILED. An error code is passed in the void *edata argument of contp. The error code can be:

  • INK_CACHE_ERROR_NOT_READY: trying to access to the cache while it's not yet initialized.

  • INK_CACHE_ERROR_NO_DOC: document does not exist in cache.

  • INK_CACHE_ERROR_DOC_BUSY: trying to read a document while another continuation is writing on it.

  • Any other value: unknown read failure

Finally, once you have performed a cache lookup, you can write into cache with INKCacheWrite. The user (contp) also has the option to cancel the action returned by INKCacheRead by using INKActionCancel.

[Note] Note

It is up to the user to read the data from the cache vc iobuffer and consume it. The cache does not bufferize the data and will not call the user back unless all the data from the cache iobuffer is consumed.

Reentrant calls are possible; in other words, the cache can call back the user (contp) in the same call.

Returns

An INKAction object if successful.

INK_ERROR_PTR if an argument is incorrect or if the API failed.