Problem/Motivation

The services module exits without calling drupal_page_footer(), which thwarts Drupal's built-in header controls and caching ability. Since caching is one of the fundamental REST constraints, this is a significant limitation.

Steps to reproduce

  • Download services project, enable REST module
  • Visit /admin/structure/services, add a REST service called "test"
  • Click "edit resources", enable the node resource
  • Visit /admin/config/development/performance, enable "cache pages for anonymous" and set "expiration of cached pages" to 1 minute
  • Log out, and request /test/node

Expected result:

  • A record in the {cache_page} table
  • response header: Cache-Control: public, max-age=60

Actual result

  • {cache_page} table is empty
  • response header: Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0

Proposed resolution

Call drupal_page_footer().

Remaining tasks

Patch needs review.

User interface changes

N/A

API changes

Module authors must call drupal_page_is_cacheable(FALSE) in their service callbacks if responses should not be cached.

Comments

kylebrowning’s picture

Category: bug » feature
grendzy’s picture

Status: Active » Reviewed & tested by the community

I'm using this patch on one of my projects with good results. We're getting caching within Drupal, and also downstream in the Akamai CDN. Here's a sample of the headers:


[dylan@mb ~]$ curl -k -v -s -o/dev/null -H "Pragma: akamai-x-get-cache-key" -H "Pragma: akamai-x-cache-on" -H "Pragma: akamai-x-cache-remote-on" -H "Pragma: akamai-x-get-true-cache-key" http://www.emmys.com/iphone/category.json
* About to connect() to www.emmys.com port 80 (#0)
* Trying 23.3.105.32... connected
> GET /iphone/category.json HTTP/1.1
> User-Agent: curl/7.23.1 (x86_64-apple-darwin11.2.0) libcurl/7.23.1 OpenSSL/1.0.1c zlib/1.2.7 libidn/1.22
> Host: www.emmys.com
> Accept: */*
> Pragma: akamai-x-get-cache-key
> Pragma: akamai-x-cache-on
> Pragma: akamai-x-cache-remote-on
> Pragma: akamai-x-get-true-cache-key
>
< HTTP/1.1 200 OK
< Server: Apache/2.2.3 (CentOS)
< X-Powered-By: PHP/5.2.17
< X-Drupal-Cache: HIT
< ETag: "1349936155-1"
< Last-Modified: Thu, 11 Oct 2012 06:15:55 +0000
< Content-Type: application/json
< Cache-Control: public, max-age=0
< Expires: Thu, 11 Oct 2012 06:40:38 GMT
< Date: Thu, 11 Oct 2012 06:40:38 GMT
< Transfer-Encoding: chunked
< X-Cache: TCP_MEM_HIT from a23-3-105-28.deploy.akamaitechnologies.com (AkamaiGHost/6.8.4.3-9847878) (-)
< X-Cache-Key: /L/1483/82472/1m/www.emmys.com/iphone/category.json
< X-True-Cache-Key: /L/www.emmys.com/iphone/category.json
< Connection: keep-alive
< Connection: Transfer-Encoding

marcingy’s picture

This makes sense to me.

kylebrowning’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

add template