diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2013-01-23 20:50:54 -0500 | 
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2013-01-23 20:50:54 -0500 | 
| commit | 34198e71d320fe013993abff870986eafb6aa8bc (patch) | |
| tree | 5ed97b3426ab44bdc765b32f7135655204851334 /modules/gallery/helpers/data_rest.php | |
| parent | 7f0a844794fbdced45d23eb898fc0475eeef18e2 (diff) | |
Add a cache buster to all data_rest urls, add caching headers to all
data_rest responses, and check cache validity.  Fixes #1909.
Diffstat (limited to 'modules/gallery/helpers/data_rest.php')
| -rw-r--r-- | modules/gallery/helpers/data_rest.php | 25 | 
1 files changed, 23 insertions, 2 deletions
| diff --git a/modules/gallery/helpers/data_rest.php b/modules/gallery/helpers/data_rest.php index dc213510..d4f456d7 100644 --- a/modules/gallery/helpers/data_rest.php +++ b/modules/gallery/helpers/data_rest.php @@ -47,7 +47,16 @@ class data_rest_Core {        throw new Kohana_404_Exception();      } -    // We don't have a cache buster in the url, so don't set cache headers here. +    header("Content-Length: " . filesize($file)); + +    if (isset($p->m)) { +      header("Pragma:"); +      // Check that the content hasn't expired or it wasn't changed since cached +      expires::check(2592000, $item->updated); + +      expires::set(2592000, $item->updated);  // 30 days +    } +      // We don't need to save the session for this request      Session::instance()->abort_save(); @@ -84,6 +93,18 @@ class data_rest_Core {    }    static function url($item, $size) { -    return url::abs_site("rest/data/{$item->id}?size=$size"); +    if ($size == "full") { +      $file = $item->file_path(); +    } else if ($size == "resize") { +      $file = $item->resize_path(); +    } else { +      $file = $item->thumb_path(); +    } +    if (!file_exists($file)) { +      throw new Kohana_404_Exception(); +    } + +    return url::abs_site("rest/data/{$item->id}?size=$size&m=" . filemtime($file));    }  } + | 
