The CXF documentation mentions caching as Advanced HTTP:
CXF JAXRS provides support for a number of advanced HTTP features by handling If-Match, If-Modified-Since and ETags headers. JAXRS Request context object can be used to check the preconditions. Vary, CacheControl, Cookies and Set-Cookies are also supported.
I'm really interested in using (or at least exploring) these features. However, while "provides support" sounds really interesting, it isn't particularly helpful in implementing such features. Any help or pointers on how to use If-Modified-Since, CacheControl or ETags?
CXF didn't implements dynamic filtering as explained here : http://www.jalg.net/2012/09/declarative-cache-control-with-jax-rs-2-0
And if you use to return directly your own objects and not CXF Response, it's hard to add a cache control header.
I find an elegant way by using a custom annotation and creating a CXF Interceptor that read this annotation and add the header.
So first, create a CacheControl annotation
Then, add this annotation to your CXF operation method (interface or implementation it works on both if you use an interface)
Then create a CacheControl interceptor that will handle the annotation and add the header to your response.
Finally configure CXF to use your interceptor, you can find all the needed information here : http://cxf.apache.org/docs/interceptors.html
Hope it will help.
Loïc
With the forthcoming JAX-RS 2.0 it will be possible to apply Cache-Control declaratively, as explained in http://jalg.net/2012/09/declarative-cache-control-with-jax-rs-2-0/
You can already test this at least with Jersey. Not sure about CXF and RESTEasy though.
Actually, the answer isn't specific to CXF - it's pure JAX-RS: