You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Leif Hedstrom <zw...@apache.org> on 2014/02/05 23:41:17 UTC

[API Review] Add TSHttpTxnIsCacheable()

Hi all,

I’d like to add this new API, TSHttpTxnIsCacheable(), as discussed on this Jira:

	https://issues.apache.org/jira/browse/TS-1622


The reason for this API is for a specific plugin that I’m developing, a “Background Fetcher”, which listens for 206 responses from Origin, and replays them to allow the server to automatically fill the object in cache. This is discussed in somewhat in

	https://issues.apache.org/jira/browse/TS-974


(which talks about partial cache objects, but that turns out to be slightly more difficult). I have also filed a new Jira specifically for this plugin:

	https://issues.apache.org/jira/browse/TS-2554

 I think there’s room for both solutions long term, hence I think this API fills a real need. In addition, I think this API is generally useful for any plugin that wants to try to do something clever upon detecting cache misses. I could imagine for example the page speed plugin to use this, and perhaps even the ESI plugin (but I have no real code examples for that).

The new API is:

	tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response);


The txnp argument is required, because the underlying code needs a txnp to get to the various configurations related to deciding upon cacheability. The request and response parameters are optional, a NULL value means to use the ‘default’ from the transaction, which equates to

	request -> the client request
	response -> the origin server response

During discussions with James and Bryan, a concern is that we require the txnp, but I don’t see an easy way around that. Another concern was to be able to test cache ability for only a request (or a response) header. However, this is fairly easily done, and the reason why you can provide either of these yourself. It’s very easy to simply create a “dummy” response header, which has nothing but e.g. “200 OK\r\nCache-Control: max-age=31536000”, and use that as a simulated response.

The Doxygen docs for the API is attached in the Jira above, and below as well.

There are no ABI / API incompatibilities with this patch.

Comments please.

— Leif

  /**
    Test whether a request / response header pair would be cacheable under the current
    configuration. This would typically be used in TS_HTTP_READ_RESPONSE_HDR_HOOK, when
    you have both the client request and server response ready.

    @param txnp the transaction pointer
    @param request the client request header. If NULL, use the transactions client request.
    @param response the server response header. If NULL, use the transactions origin response.

    @return 1 if the request / response is cacheable, 0 otherwise
  */
  tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response);



Re: [API Review] Add TSHttpTxnIsCacheable()

Posted by Otto van der Schaaf <os...@gmail.com>.
+1
I too think it could prove really useful in that light - allowing for tighter integration.

Otto

On 05 Feb 2014, at 23:41, Leif Hedstrom <zw...@apache.org> wrote:

>  I could imagine for example the page speed plugin to use this


Re: [API Review] Add TSHttpTxnIsCacheable()

Posted by Leif Hedstrom <zw...@apache.org>.
On Feb 6, 2014, at 9:20 AM, Shu Kit Chan <ch...@gmail.com> wrote:

> so for example, this API will honor settings in records.config, e,g,
> 
> proxy.config.http.cache.cache_responses_to_cookies
> 
> proxy.config.http.negative_caching_enabled
> 
> and tell us whether it is cacheable or not. Right?


Correct. It uses the underlying core API in HttpTransact:

	bool HttpTransact::is_response_cacheable(State* s, HTTPHdr* request, HTTPHdr* response) 


— Leif

Re: [API Review] Add TSHttpTxnIsCacheable()

Posted by Shu Kit Chan <ch...@gmail.com>.
so for example, this API will honor settings in records.config, e,g,

proxy.config.http.cache.cache_responses_to_cookies

proxy.config.http.negative_caching_enabled

and tell us whether it is cacheable or not. Right?

That should be useful. +1




On Wed, Feb 5, 2014 at 3:01 PM, Leif Hedstrom <zw...@apache.org> wrote:

>
> On Feb 5, 2014, at 3:57 PM, Ethan Lai <yz...@yahoo.com> wrote:
>
> > Leif,
> >
> > Very useful!!!  This is what I need in collapsed connection plugin.
>
> Yeah, that makes total sense.
>
>
> > Which ts version will this API be available? 5.0 ?
>
> This would land in a few days, as long as it passes the review phase. That
> means yes, it would be in v5.0.0.
>
> >
> > BTW, My collapsed connection plugin is almost done, could you help me to
> review it?
>
> Yeah, post it on a Jira, and/or make a github branch and submit it to the
> mailing list for review. I'm cc:ing dev@ here as well, I hope you don't
> mind.
>
> -- leif
>
>

Re: [API Review] Add TSHttpTxnIsCacheable()

Posted by Leif Hedstrom <zw...@apache.org>.
On Feb 5, 2014, at 3:57 PM, Ethan Lai <yz...@yahoo.com> wrote:

> Leif,
> 
> Very useful!!!  This is what I need in collapsed connection plugin.

Yeah, that makes total sense.


> Which ts version will this API be available? 5.0 ?

This would land in a few days, as long as it passes the review phase. That means yes, it would be in v5.0.0.

> 
> BTW, My collapsed connection plugin is almost done, could you help me to review it?

Yeah, post it on a Jira, and/or make a github branch and submit it to the mailing list for review. I’m cc:ing dev@ here as well, I hope you don’t mind.

— leif