Etomite Community Forums: syncSite - Etomite Community Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

syncSite clears the site cache

#1 User is offline   Cris D. 

  • Loves Etomite Forums!
  • PipPipPipPip
  • Group: Member
  • Posts: 1,076
  • Joined: 10-August 06
  • Gender:Not Telling

Posted 03 March 2009 - 07:04 PM

This function clears the site cache. Usually this is handled by the etomite manager so the average site will never need this function. However, if you have code that is making changes to the content of a page, a snippet, chunk or template that is cached, using this function will delete the cached version.

Depending on the size of your site and the number of cached pages, there could be quite a bit of overhead in using this function, so be very selective in its use. Although the function says that it rebuilds the site cache, it does rebuild the site settings, aliases, document content types, templates, chunks, snippets but not individual pages. Individual page cache files are rebuilt when they are visited for the first time after a cache clear.

This function also listens for sheduled publishing and unpublishing to keep the cache in sync.

function syncsite() {
  // clears and rebuilds the site cache
  // added in 0.6.1.1
  // Modified 2008-03-17 by Ralph for improved cachePath handling
	include_once("./manager/processors/cache_sync.class.processor.php");
	$sync = new synccache();
	$sync->setCachepath("assets/cache/");
	$sync->setReport(false);
	$sync->emptyCache();
  }


An example of use:
$formData=$_POST['form'];
$formData=sanitiseData($formData);//a fictitional magic function :)
$etomite->putIntTableRows($formData,'etomite_site_content');
$etomite->syncsite();
return "Data saved, page cache has been refreshed.";


#2 User is offline   Cris D. 

  • Loves Etomite Forums!
  • PipPipPipPip
  • Group: Member
  • Posts: 1,076
  • Joined: 10-August 06
  • Gender:Not Telling

Posted 07 March 2009 - 11:48 AM

Related function clearCache()

This clears only the document cache files instead of the entire site cache (which includes snippets, system settings, chunks etc). clearCache() is almost the same as syncsite(), but is more selective with what is deleted. If you are only making changes to page content (outside of the manager), this function is easier on your server.
an example of use:

$cache=$etomite->clearCache();
if($cache) { return "Cache Cleared.";
} 
else
{ 
				  return"There is no cached documents to clear.";
				}


function clearCache() {
  // deletes all cached documents from the ./assets/acahe directory
	$basepath=dirname(__FILE__);
	if (@$handle = opendir($basepath."/assets/cache")) {
	  $filesincache = 0;
	  $deletedfilesincache = 0;
	  while (false !== ($file = readdir($handle))) {
		if ($file != "." && $file != "..") {
		  $filesincache += 1;
		  if (preg_match ("/\.etoCache/", $file)) {
			$deletedfilesincache += 1;
			unlink($basepath."/assets/cache/".$file);
		  }
		}
	  }
	  closedir($handle);
	  return true;
	} else {
	  return false;
	}
  }


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users