Permalink
Browse files

ENHANCEMENT Added ManifestBuilder::$cache_expiry_mins

API CHANGE Deprecated URL parameter ?buildmanifest=1 (please use ?flush=1)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63182 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 97263cd commit d7a4ae6a8f434efcbbbc4f72105b3cf2866655ae @chillu chillu committed Sep 28, 2008
Showing with 23 additions and 11 deletions.
  1. +23 −11 core/ManifestBuilder.php
View
34 core/ManifestBuilder.php
@@ -56,26 +56,38 @@ class ManifestBuilder {
);
/**
- * Returns true if the manifest file should be regenerated
+ * @var int $cache_expiry_mins Specifies the time (in minutes) until a rebuild
+ * of the manifest cache is forced.
+ * @usedby self::staleManifest()
+ */
+ public static $cache_expiry_mins = 60;
+
+ /**
+ * Returns true if the manifest file should be regenerated,
+ * by asserting one of the following conditions:
+ * - Manifest cache file doesn't exist
+ * - The modification time of the webroot folder is newer than the cache file
+ * - The cache file is older than {@link self::$cache_expiry_mins}
+ * - A cache rebuild is forced by the "?flush=1" URL parameter
+ *
+ * Checked on every request handled by SilverStripe in main.php or cli-script.php.
*
- * @return bool Returns TRUE if the manifest file should be regenerated,
- * otherwise FALSE.
+ * @return bool Returns TRUE if the manifest file should be regenerated, otherwise FALSE.
*/
static function staleManifest() {
- /*if(Director::isDev() || Director::isTest())
- $lastEdited = Filesystem::folderModTime(".", array('ss','php'));
- else*/
- $lastEdited = filemtime("../");
+ $lastEdited = filemtime(BASE_PATH);
- return !file_exists(MANIFEST_FILE)
+ return (
+ !file_exists(MANIFEST_FILE)
|| (filemtime(MANIFEST_FILE) < $lastEdited)
- || (filemtime(MANIFEST_FILE) < time() - 3600)
- || isset($_GET['buildmanifest']) || isset($_GET['flush']);
+ || (filemtime(MANIFEST_FILE) < time() - 60 * self::$cache_expiry_mins)
+ || isset($_GET['flush'])
+ );
}
/**
- * Generates a new manifest file and saves it to {@link MANIFEST_FILE}
+ * Generates a new manifest file and saves it to {@link MANIFEST_FILE}.
*/
static function compileManifest() {
// Config manifest

0 comments on commit d7a4ae6

Please sign in to comment.