[2011-07-12] Error in RebuildStaticCacheTask.php ?! #324

Closed
silverstripe-issues opened this Issue Apr 3, 2013 · 2 comments

Comments

Projects
None yet
2 participants

created by: tekilla83
created at: 2011-07-12
original ticket: http://open.silverstripe.org/ticket/6679


In an older Version I found:

if($removeAll && file_exists("../cache")) {
 echo "Removing old cache... \n";
 flush();
 Filesystem::removeFolder("../cache", true);
 echo "done.\n\n";
}

in 2.4.5 Line 87 it says:

if($removeAll && !isset($_GET['urls']) && $start == 0 && file_exists("../cache")) {
         echo "Removing stale cache files... \n";
         flush();
         if (FilesystemPublisher::$domain_based_caching) {
            // Glob each dir, then glob each one of those
            foreach(glob(BASE_PATH . '/cache/*', GLOB_ONLYDIR) as $cacheDir) {
               foreach(glob($cacheDir.'/*') as $cacheFile) {
                  $searchCacheFile = trim(str_replace($cacheBaseDir, '', $cacheFile), '\/');
                  if (!in_array($searchCacheFile, $mappedUrls)) {
                     echo " * Deleting $cacheFile\n";
                     @unlink($cacheFile);
                  }
               }
            }
         } else {

         }

         echo "done.\n\n";
      }

Why is the else code empty?
FilesystemPublisher::$domain_based_caching is false for default. Shouldn't there be somethink like this:

Filesystem::removeFolder($cacheBaseDir, true);
touch($cacheBaseDir.'/lock');

If I set:

FilesystemPublisher::$domain_based_caching = true;

In my config.php and changed Link() to AbsoluteLink() in Page->subPagesToCache():

function subPagesToCache($translate='all') {
      $urls = array();
      // add current page
      if($this->nocache!=1){
         $urls[] = $this->AbsoluteLink();
         // add translations
         if($translate=='all'){
            $translations = Translatable::getTranslations();
            if(is_object($translations)){
               foreach($translations as $translation){
                  $urls[] = $translation->AbsoluteLink();
               }
            }
         }
         // cache the RSS feed if comments are enabled
         if ($this->ProvideComments) {
            $urls[] = Director::absoluteBaseURL() . "pagecomment/rss/" . $this->ID;
         }
      }
      return $urls;

It doesn't deleting anything when I make a dev/buildcache so probably there is another error.

PS: I posted it already here: http://silverstripe.org/general-questions/show/17445#post305397

comment by: @sminnee (sminnee)
created at: 2012-03-25


RebuildStaticCacheTask clearly needs to be tidied up.

Contributor

simonwelsh commented Mar 16, 2014

Static publisher is now a separate module.

@simonwelsh simonwelsh closed this Mar 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment