asolfre / appengine-rest-server

Automatically exported from code.google.com/p/appengine-rest-server
Other
0 stars 0 forks source link

Query Cache stores one page, either XML or JSON #49

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set HTTP "Accept: application/xml".
2. Query for a model, e.g. /rest/user/?fgt_age=30
3. Get an XML document response.
4. Change to HTTP "Accept: application/json".
5. Query the same URL, e.g. /rest/user/?fgt_age=30
6. Get the cached XML document response, again, not JSON.

What is the expected output? What do you see instead?

The cached page is the same MIME type as the first time it was requested. So, a 
cached XML document is returned for a JSON request.

The MIME type should be mangled into the memcache key, i.e. self.request.url, 
so that the XML and JSON pages are unique. I did this on my local copy of 
./rest/__init__.py to make:

out_mime_type= self.request.accept.best_match(self.output_content_types)
cache_key = self.request.url + out_mime_type

That works well enough.

What version of the product are you using? On what operating system?

I use the latest SVN /trunk/ download.

Please provide any additional information below.

Original issue reported on code.google.com by adroffner on 13 Jan 2012 at 6:06

GoogleCodeExporter commented 9 years ago
yep, that did occur to me at one point in time after i implemented the json 
support.  figured relatively few people would be querying for multiple mime 
types (and using the caching), so it was low on the priority list.  this is a 
relatively simple fix though, thanks.

Original comment by jahlborn@gmail.com on 13 Jan 2012 at 11:51

GoogleCodeExporter commented 9 years ago
actually, after looking at this more closely, it turns out this is not as 
simple as it seems.  unfortunately, caching GET calls for individual model 
properties is a bit more complexv (determining the mime type is more 
complicated than just calling best_match).

Original comment by jahlborn@gmail.com on 18 Jan 2012 at 3:26

GoogleCodeExporter commented 9 years ago
I've figured out how to fix this so that a caller will not get an incorrectly 
formatted response.  The cache will still only cache one response per url, 
however, it maintains the original request "accept" header with the cached 
info.  if an incoming request does not have the same accept header, the cached 
response will not be returned.

while this may not be "perfect" in terms of caching (multiple clients using 
different accept headers for the same header will thrash the cache), it _will_ 
ensure that callers always get the correct response type.  and in most 
scenarios, i wouldn't imagine that an application is getting a lot of requests 
for the same url w/ different accept headers.

Original comment by jahlborn@gmail.com on 6 Jul 2012 at 4:28

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r109.

Original comment by jahlborn@gmail.com on 6 Jul 2012 at 4:35