Changeset - 1c87613b625c
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 14 years ago 2012-02-27 10:15:18
ohnobinki@ohnopublishing.net
Add caching support for section autocomplete requests.
2 files changed with 29 insertions and 2 deletions:
0 comments (0 inline, 0 general)
auto.php
Show inline comments
 
@@ -35,7 +35,26 @@ require_once('inc/school.inc');
 
require_once('inc/class.page.php');
 
require_once('inc/class.course.inc');
 

	
 
page::session_start();
 
/*
 
 * Set the Expires and Cache-Control headers -- only if we're getting
 
 * a request which does not rely on the contents of $_SESSION.
 
 */
 
if (!empty($_GET['school']) && !empty($_GET['semester']))
 
  {
 
    header('Expires: ' . gmdate(DATE_RFC1123, time() + 600));
 
    header('Cache-Control: max-age=600, public');
 
    $cache_limiter = 'public';
 
  }
 
else
 
  {
 
    /*
 
     * Tell the caches that the user's cookies affect the cacheability
 
     * since the user did not specify the current semester/school.
 
     */
 
    header('Vary: Cookie');
 
    $cache_limiter = 'private';
 
  }
 
page::session_start($cache_limiter);
 

	
 
if (isset($_REQUEST['txt'])) {
 
  header('Content-Type: text/plain; encoding=utf-8');
 
@@ -88,6 +107,9 @@ if (!$getsections && count($term_parts) 
 
      clean_empty_exit();
 
    }
 
    $departments = unserialize(file_get_contents($dept_file));
 
    $departments_mtime = filemtime($dept_file);
 
    if ($departments_mtime)
 
      header('Last-Modified: ' . gmdate(DATE_RFC1123, $departments_mtime));
 
    $json_depts = array();
 
    if (!empty($departments) && is_array($departments[0]))
 
      {
inc/class.page.php
Show inline comments
 
@@ -645,13 +645,18 @@ class page
 
   * Used to make sure that different areas of our code don't call
 
   * session_start() multiple times and to make it easier to ensure
 
   * that session_start() is called at least before it's needed.
 
   *
 
   * \param $cache_limiter
 
   *   Specify the sort of session-related cache limitation is used,
 
   *   see session_cache_limiter().
 
   */
 
  public static function session_start()
 
  public static function session_start($cache_limiter = 'nocache')
 
  {
 
    static $session_started = FALSE;
 

	
 
    if (!$session_started)
 
      {
 
	session_cache_limiter($cache_limiter);
 
	session_name('slate_permutate');
 
	session_start();
 
	$session_started = TRUE;
0 comments (0 inline, 0 general)