1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Improve cache behaviors for font files and other nonstandard resource types

Summary:
Ref T10843. There are actually two separate notions of cacheability here:

  - Is this cacheable by the browser (e.g., should we emit "Expires: long in the future")?
  - Is this cacheable locally (e.g., should we stick it in APC, or just read it off disk every time)?

These got a little mixed up by D15775, so we aren't currently emitting proper "Expires" headers on font files and a few other resource types.

Straighten this out so that we "Expires" these unusual resources correctly.

Test Plan: Verified that `.woff` files get a proper "Expires" header now, not just CSS/JS.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10843

Differential Revision: https://secure.phabricator.com/D15807
This commit is contained in:
epriestley 2016-04-27 06:42:32 -07:00
parent 63bbe6b129
commit fbc4967154

View file

@ -50,8 +50,8 @@ abstract class CelerityResourceController extends PhabricatorController {
// is not, refuse to cache this resource. This avoids poisoning caches // is not, refuse to cache this resource. This avoids poisoning caches
// and CDNs if we're getting a request for a new resource to an old node // and CDNs if we're getting a request for a new resource to an old node
// shortly after a push. // shortly after a push.
$is_cacheable = ($hash === $expect_hash) && $is_cacheable = ($hash === $expect_hash);
$this->isCacheableResourceType($type); $is_locally_cacheable = $this->isLocallyCacheableResourceType($type);
if (AphrontRequest::getHTTPHeader('If-Modified-Since') && $is_cacheable) { if (AphrontRequest::getHTTPHeader('If-Modified-Since') && $is_cacheable) {
// Return a "304 Not Modified". We don't care about the value of this // Return a "304 Not Modified". We don't care about the value of this
// field since we never change what resource is served by a given URI. // field since we never change what resource is served by a given URI.
@ -60,7 +60,7 @@ abstract class CelerityResourceController extends PhabricatorController {
$cache = null; $cache = null;
$data = null; $data = null;
if ($is_cacheable && !$dev_mode) { if ($is_cacheable && $is_locally_cacheable && !$dev_mode) {
$cache = PhabricatorCaches::getImmutableCache(); $cache = PhabricatorCaches::getImmutableCache();
$request_path = $this->getRequest()->getPath(); $request_path = $this->getRequest()->getPath();
@ -168,7 +168,7 @@ abstract class CelerityResourceController extends PhabricatorController {
* @param string Resource type. * @param string Resource type.
* @return bool True to enable caching. * @return bool True to enable caching.
*/ */
private function isCacheableResourceType($type) { private function isLocallyCacheableResourceType($type) {
$types = array( $types = array(
'js' => true, 'js' => true,
'css' => true, 'css' => true,