CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Scalability (Moderator: Donald Lobo) »
  • Make public pages cachable
Pages: [1]

Author Topic: Make public pages cachable  (Read 2325 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Make public pages cachable
October 31, 2012, 03:03:09 am
CIviCRM pages are served with

Code: [Select]
Server: nginx/1.1.19
Date: Wed, 31 Oct 2012 08:59:47 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.10-1ubuntu3.4
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Wed, 31 Oct 2012 08:59:45 +0000
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1351673985"
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Content-Encoding: gzip

For one site that will have a lot of traffic, we have put civi behind a proxy. To make the most of it, we need to change that header for public pages served to anonymous

There is an option in drupal to serve cached pages, but doesn't apply to civi.

Where are these headers set in civi?
have been greping it for half an hour, can only find it in CRM/Utils/System.php and export, but only when downloading


Anyway, that's my plan:

have a new extension publiccache that
1) check if the user is anonymous
if it's the case, set the header() so expire is in the future and that it got the right header stuff so it's cachable

2) if a user registers (or is authenticated in general), set a a cookie civicrm-user=Y

2) on my reverse proxy (nginx), set to bypass the cache if civicrm-user and is set and otherwise serve the cached version

Ideally, the url generated for the public pages (contrib is my main interested here) would contain an extra param timestamp=xxx) that would be modified everytime the page is modified so we are sure not to provide a link to an old cached version, but if complicated, we can skip that and add this extra param manually

What do you think?




« Last Edit: October 31, 2012, 03:15:09 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Make public pages cachable
October 31, 2012, 03:06:02 am
A somehow related improvement:
smarty allows to cache result. For those that aren't behind a proxy, might be useful.
http://www.smarty.net/docsv2/en/caching.tpl

To work, it would need to know the template early in the request (before starting all the sql queries to fetch the data) so it can do a is_cached() and returning the cached value.

Not sure we can reliably do that. Input welcome too

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Make public pages cachable
October 31, 2012, 05:11:50 am
More info: we did a test and configured nginx proxy to cache the page. Serves fine and is more than 5 times faster. And it was over a ssl connection that seems to take a fair bit of the connection time so would be even more impressive over http probably. But...

because the cached page contains a qFkey and/or because the cookies are not always there, you get a nice error message when you submit the form. Not so good.

Profiles are able to generate a static html page, so it must be possible somehow for contrib, isn't it?

I'll discuss it with you on IRC. Ping me when you are available.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Make public pages cachable
October 31, 2012, 09:45:28 am

It is possible for contrib, it just needs some code changes to allow a standalone form :)

This will be great in 4.3 if we have standalone forms along with JS client side validation (work that micah @ eff has done). This will allow folks (and spammers) to fill and validate the first page without hitting the server

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

ylavoie

  • I’m new here
  • *
  • Posts: 19
  • Karma: 0
    • Regroupement de l'industrie électronique du Québec
  • CiviCRM version: 4.2.4
  • CMS version: Joomla 2.5.7
  • MySQL version: 5.5.24
  • PHP version: 5.3.10
Re: Make public pages cachable
February 01, 2013, 06:01:40 pm
Donald,

Any idea if this will be able to make it for 4.3? I can't wait...

Yves

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Make public pages cachable
February 02, 2013, 08:14:03 am

a lot of micah's changes went in. But i dont think anyone worked to ensure that those pages were cache-able

might be a good project for 4.4

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Scalability (Moderator: Donald Lobo) »
  • Make public pages cachable

This forum was archived on 2017-11-26.