public function onBeforeInit()
 {
     // Determine if this page is of a non-cacheable type
     $ignoredClasses = DynamicCache::config()->ignoredPages;
     $ignoredByClass = false;
     if ($ignoredClasses) {
         foreach ($ignoredClasses as $ignoredClass) {
             if (is_a($this->owner->data(), $ignoredClass, true)) {
                 $ignoredByClass = true;
                 break;
             }
         }
     }
     $isStage = ($stage = Versioned::current_stage()) && $stage !== 'Live';
     // Set header disabling caching if
     // - current page is an ignored page type
     // - current_stage is not live
     if ($ignoredByClass || $isStage) {
         $header = DynamicCache::config()->optOutHeaderString;
         header($header);
     }
     // Flush cache if requested
     if (isset($_GET['flush']) || isset($_GET['cache']) && $_GET['cache'] === 'flush' && Permission::check('ADMIN')) {
         DynamicCache::inst()->clear();
     }
 }
 public function onBeforeInit()
 {
     // If not on live site, set header disabling caching to prevent caching of draft content
     if (($stage = Versioned::current_stage()) && $stage !== 'Live') {
         $header = DynamicCache::config()->optOutHeaderString;
         header($header);
     }
 }
 /**
  * Shortcut for handling configuration parameters
  */
 public function __call($name, $arguments)
 {
     if (preg_match('/^(?<op>(get)|(set))_(?<arg>.+)$/', $name, $matches)) {
         $field = $matches['arg'];
         Deprecation::notice('3.1', "Call DynamicCache::config()->{$field} directly");
         if ($matches['op'] === 'set') {
             return DynamicCache::config()->{$field} = $arguments[0];
         } else {
             return DynamicCache::config()->{$field};
         }
     }
     return parent::__call($name, $arguments);
 }
Ejemplo n.º 4
0
ini_set('error_log', Director::baseFolder() . '/error.log');
SS_Log::add_writer(new SS_LogFileWriter(Director::baseFolder() . '/silverstripe.log'), SS_Log::INFO, '<=');
// Set a cache (disabled in dev mode anyway)
//HTTP::set_cache_age(60 * 30); // 30 min
//Might be better to add this to "Page::init"
// Configure according to environment
if (Director::isDev()) {
    // Display all errors
    error_reporting(-1);
    // Add a debug logger
    SS_Log::add_writer(new SS_LogFileWriter(Director::baseFolder() . '/debug.log'), SS_Log::DEBUG, '=');
    // Send emails to admin
    Email::send_all_emails_to(Email::config()->admin_email);
    // Disable DynamicCache
    if (class_exists('DynamicCache')) {
        DynamicCache::config()->enabled = false;
    }
    // See where are included files
    Config::inst()->update('SSViewer', 'source_file_comments', true);
    // Fix this issue https://github.com/silverstripe/silverstripe-framework/issues/4146
    if (isset($_GET['flush'])) {
        i18n::get_cache()->clean(Zend_Cache::CLEANING_MODE_ALL);
    }
} else {
    // In production, sanitize php environment to avoid leaking information
    ini_set('display_errors', false);
    // Hide where are included files
    Config::inst()->update('SSViewer', 'source_file_comments', false);
    // Warn admin if errors occur
    SS_Log::add_writer(new SS_LogEmailWriter(Email::config()->admin_email), SS_Log::ERR, '<=');
}