[Fusionforge-commits] r14684 - trunk/src/common/include

Alain Peyrat aljeux at fusionforge.org
Wed Oct 19 18:42:06 CEST 2011


Author: aljeux
Date: 2011-10-19 18:42:05 +0200 (Wed, 19 Oct 2011)
New Revision: 14684

Modified:
   trunk/src/common/include/TextSanitizer.class.php
Log:
Cache stripTags() using apc if present to speedup frontpage

Modified: trunk/src/common/include/TextSanitizer.class.php
===================================================================
--- trunk/src/common/include/TextSanitizer.class.php	2011-10-19 16:42:00 UTC (rev 14683)
+++ trunk/src/common/include/TextSanitizer.class.php	2011-10-19 16:42:05 UTC (rev 14684)
@@ -45,7 +45,7 @@
 
 require_once('HTMLPurifier.auto.php');
 
-Class TextSanitizer extends Error {
+class TextSanitizer extends Error {
 
 
 	/**
@@ -221,12 +221,24 @@
 	}
 
 	function stripTags ($text, $allowed='br,p,li,ul') {
+		// Try apc caching first (if possible).
+		if (function_exists('apc_fetch')) {
+			$key = 'stripTags.'.md5($text);
+			$cached = apc_fetch($key);
+			if ($cached) {
+				return $cached;
+			}
+		}
+
 		$config = HTMLPurifier_Config::createDefault();
 		$config->set('Cache.DefinitionImpl', NULL);
 		$config->set('HTML.Allowed', $allowed);
 		$purifier = new HTMLPurifier($config);
 		$text = $purifier->purify($text);
 
+		if (function_exists('apc_store') && $key) {
+			apc_store($key, $text, 3600);
+		}
 		return $text;
 	}
 




More information about the Fusionforge-commits mailing list