Why doesn't this cache?

Poster Content
nk4um User
Posts: 101
March 11, 2010 18:01Hrm
Ok, but ...

This is really confusing and unintuitive.  I suspected the answer was something like this, but I could find nothing in the documentation that suggests the implication of something as simple and common as getting parameters.

But more importantly, why is this useful?  The result of this is that getting the parameters anywhere in your call stack renders everything above it completely non-cachable, regardless of whether the value is different, important, or even used.  I thought the benefit of the ''httpRequest'' space was that you could easily get at request info from a very deep level without needing to pass things down at every level, but now my advice would have to be don''t use it except at the very highest level.

In addition to that, why does the value even get (and stay) cached if there''s no way to ever get to it?  It just uselessly fills up the cache with inaccessible junk.  (And confuses anyone who might try to understand what''s going on.)
nk4um Moderator
Posts: 485
March 11, 2010 12:47It the scope
Hi Jeff, although the resource representation isn''t expired in your example the scope of response is different each time it is requested. This is because you have forced inclusion of the http request address space by resolving a resource from there. This in effect means that you are actually computing the representation in a different place and therefore the value you have in the cache cannot be validly used. For more details and example see my blog post:

http://durablescope.blogspot.com/2009/11/caching-how-and-why-it-works.html

One way to change the scoping and hence the cachability is to have a layer in your system which extracts the params from the http request space and puts them onto the request. (you could use the mapper to do this). That way for an identical value of a parameter you would be able to retrieve the response representation from cache (all other factors willing)

Cheers, Tony
nk4um User
Posts: 101
March 11, 2010 08:41Why doesn't this cache?
A confusing piece of behavior I ran into. 

context.source("httpRequest:/params");
response=context.createResponseFrom("xyz:"+Math.round(Math.random()*1000));
response.setExpiry(response.EXPIRY_DEPENDENT);
context.setResponse(response);

This is close to as simple a groovy script as you can have.  The expected behavior is that it will return a string like "xyz:123" once, cache that value, and after that keep returning the same result.  It doesn''t.  You get a new result every time.  My first thought was that ''httpRequest:/params'' is always expired, which would prevent something dependent on it from getting cached.  So I tried instead

context.source("httpRequest:/params");
response=context.createResponseFrom("xyz:"+Math.round(Math.random()*1000));
response.setExpiry(response.EXPIRY_NEVER);
context.setResponse(response);

But the result is the same - a new random number every time.  I checked with the visualizer, and the uppermost resource indicates that it is not expired, yet it is not retrieved from cache.  And the representation cache shows many instances of the same resource.

So what''s going on?  Does any access of http request parameters simply render a request completely non-cacheable, counter to both reasonable expectations and an explicit declaration that it is cacheable forever?