cancel
Showing results for 
Search instead for 
Did you mean: 

How to set no-cache for a host/URL with TS when caching is enabled

SOLVED
crackerjack
Occasional Contributor

How to set no-cache for a host/URL with TS when caching is enabled

Hi @ all,

once again a question ...

I´ve a virtual Server with Content caching enabled, all is working fine ...

This virtual Server is used by many pools, defined via TS-Rules,

for eg.




if( string.contains( http.getheader( "host" ), "test.com" ) ){


        pool.use( "pool-1" );



if( string.contains( http.getheader( "host" ), "anothertest.com" ) ){


        pool.use( "pool-2" );



and so on.

Now I want to set "no-cache" only for host test.com for example ...

so overall caching should be enabled, but for this host it should be disabled.

I found in TS-Guide the Syntax "http.cache.disable()

but I don´t know the exact Syntax to use ...

perhaps somebody could help me here ?

Regards,

Michael

1 ACCEPTED SOLUTION

Accepted Solutions
jochenmaurer
Contributor

Re: How to set no-cache for a host/URL with TS when caching is enabled

depending on your requirements ("do not cache if a named cookie is set") , my solution would be:


if (http.getCookie( "somename") != "" ){


     http.cache.disable();


}


you have to use the name of the cookie as a parameter for http.getcookie, it will return a empty string if this cookie is not found.

View solution in original post

3 REPLIES 3
dnahas
Contributor

Re: How to set no-cache for a host/URL with TS when caching is enabled

Take a look at Feature Brief: Stingray Content Caching by for an example and more information on Content Caching.



$hostheader = http.getHostHeader();



if( $hostheader == "www.example.com" ) {


   pool.select( "Pool-1" );


   http.cache.disable();


} else if ( $hostheader == "www.test.com" ) {


   pool.select( "Pool-2" );


}


* Note the change in the pool command to use the the pool.select function.  The pool.use function Selects a pool to load-balance this connection with, and stops processing any more rules

crackerjack
Occasional Contributor

Re: Re: How to set no-cache for a host/URL with TS when caching is enabled

Hi David,

thanks for that, it seems to be working ...

another question for almost the same problem ...

When a website has a certain cookie inside, for me, named "somename", and I want this site not to be cached,

hope, I can realize that with TS too ... ?

My idea was something like this:


if( http.getcookie( "" ) == "somename" ){



        http.setResponseHeader( "Cache-Control", "no-cache" );


}



or it´s better with hostname


if( http.getheader( "host" ) == "test.com"


        && http.getcookie( "" ) == "somename" ){


        http.setResponseHeader( "Cache-Control", "no-cache" );



}



... second idea:


if( http.getheader( "host" ) == "test.com"


        && http.getcookie( "" ) == "somename" ){


        http.cache.disable(); 


}




Which one is the best for my case?

Regards,

Michael

jochenmaurer
Contributor

Re: How to set no-cache for a host/URL with TS when caching is enabled

depending on your requirements ("do not cache if a named cookie is set") , my solution would be:


if (http.getCookie( "somename") != "" ){


     http.cache.disable();


}


you have to use the name of the cookie as a parameter for http.getcookie, it will return a empty string if this cookie is not found.