Home

Traffic Server Software Developers Kit

Guide to the Cache API

The cache API enables plugins to read, write, and remove objects in the Traffic Server cache. All cache APIs are keyed by an object called an INKCacheKey; cache keys are created via INKCacheKeyCreate; keys are destroyed via INKCacheKeyDestroy. Use INKCacheKeyDigestSet to set the hash of the cache key.

Note that the cache APIs differentiate between HTTP data and plugin data. The cache APIs do not allow you to write HTTP docs in the cache; you can only write plugin-specific data (a specific type of data that differs from the HTTP type).

Example:

    const unsigned char *key_name = "example key name";

    INKCacheKey key;
    INKCacheKeyCreate (&key);
    INKCacheKeyDigestSet (key, (unsigned char *) key_name , strlen(key_name));
    INKCacheKeyDestroy (key);

How to Do a Cache Read

INKCacheRead does not really read - it is used for lookups (see the sample Protocol plugin). Possible callback events include:

  • INK_EVENT_CACHE_OPEN_READ - indicates the lookup was successful. The data passed back along with this event is a cache vconnection that can be used to initiate a read on this keyed data.

  • INK_EVENT_CACHE_OPEN_READ_FAILED - indicates the lookup was unsuccessful. Reasons for this event could be that another continuation is writing to that cache location, or the cache key doesn't refer to a cached resource. Data payload for this event indicates the possible reason the read failed (INKCacheError).