In the example below, suppose there is a cache hit and the cache
returns a vconnection that enables you to read the document from cache. To
do this, you need to prepare a buffer (cache_bufp
)
to hold the document; meanwhile, use
INKVConnCachedObjectSizeGet
to find out the actual
size of the document (content_length
). Then,
issue INKVConnRead
to read the document
with the total data length required as
content_length
. Assume the following data:
INKIOBuffer cache_bufp = INKIOBufferCreate (); INKIOBufferReader cache_readerp = INKIOBufferReaderAlloc (out_bufp); INKVConn cache_vconnp = NULL; INKVIO cache_vio = NULL; int content_length = 0;
In the INK_CACHE_OPEN_READ
handler:
cache_vconnp = (INKVConn) data; INKVConnCachedObjectSizeGet (cache_vconnp, &content_length); cache_vio = INKVConnRead (cache_vconn, contp, cache_bufp, content_length);
In the INK_EVENT_VCONN_READ_READY
handler:
(usual VCONN_READ_READY handler logic) int nbytes = INKVIONBytesGet (cache_vio); int ntodo = INKVIONTodoGet (cache_vio); int ndone = INKVIONDoneGet (cache_vio); (consume data in cache_bufp) INKVIOReenable (cache_vio);
Do not try to get continuations or VIOs from
INKVConn
objects for cache vconnections. Also
note that the following APIs can only be used on transformation
vconnections and must not be used on cache vconnections or net vconnections:
INKVConnWriteVIOGet
INKVConnReadVIOGet
INKVConnClosedGet
APIs such as INKVConnRead
,
INKVConnWrite
,
INKVConnClose
, INKVConnAbort
, and INKVConnShutdown
can be used on any kind of
vconnections.
When you are finished:
INKCacheKeyDestroy (key);