[pLog-svn] r6188 - in plog/trunk/class: dao locale template/menu

mark at devel.lifetype.net mark at devel.lifetype.net
Mon Feb 25 00:12:11 EST 2008


Author: mark
Date: 2008-02-25 00:12:10 -0500 (Mon, 25 Feb 2008)
New Revision: 6188

Modified:
   plog/trunk/class/dao/daocacheconstants.class.php
   plog/trunk/class/locale/locale.class.php
   plog/trunk/class/locale/locales.class.php
   plog/trunk/class/template/menu/menu.class.php
Log:
Add cache control to Menu and Locales
1. Now, the plugin menu item will cached with our cache manager. When request hit lifetype, the lifetype will check the menu cached or not. If yes, it will use the current cache, if not, it will generate the cache for next time use.

2. Now the pluginLocales cached with our cache manager. It can reduce a lot lt_include and array_merge in each request.

TODO: add remove cache in plugin centers, when user refresh this page, the menu and locales cache will deleted.

Modified: plog/trunk/class/dao/daocacheconstants.class.php
===================================================================
--- plog/trunk/class/dao/daocacheconstants.class.php	2008-02-25 04:06:23 UTC (rev 6187)
+++ plog/trunk/class/dao/daocacheconstants.class.php	2008-02-25 05:12:10 UTC (rev 6188)
@@ -141,9 +141,16 @@
 	    const CACHE_PRIVATE_MESSAGES = "cache_private_messages";
 	    const CACHE_PRIVATE_MESSAGES_BY_BOX_ID = "cache_private_messages_by_box_id";
 
+	    /**
+	     * locations
+	     */
 		const CACHE_LOCATION_BY_ID ="location_by_id";
 		const CACHE_LOCATIONS_BY_BLOG = "locations_by_blog";
 
+		/**
+		 * menu
+		 */
+		const CACHE_MENU_ITEMS = "cache_menu_items";
 
 	}
 ?>
\ No newline at end of file

Modified: plog/trunk/class/locale/locale.class.php
===================================================================
--- plog/trunk/class/locale/locale.class.php	2008-02-25 04:06:23 UTC (rev 6187)
+++ plog/trunk/class/locale/locale.class.php	2008-02-25 05:12:10 UTC (rev 6188)
@@ -80,7 +80,6 @@
 
 		var $_defaultFolder;
 		var $_code;	// our ISO locale code, eg. es_ES, en_UK, etc
-        var $_cache;
 		var $_messages;
         var $_charset;
 		var $_description;

Modified: plog/trunk/class/locale/locales.class.php
===================================================================
--- plog/trunk/class/locale/locales.class.php	2008-02-25 04:06:23 UTC (rev 6187)
+++ plog/trunk/class/locale/locales.class.php	2008-02-25 05:12:10 UTC (rev 6188)
@@ -74,10 +74,9 @@
                 $locale = $cache->getData( $localeCode, DaoCacheConstants::CACHE_BLOG_LOCALES );
                 if ( !$locale ) {
                     $locale = new BlogLocale( $localeCode );
+					Locales::_loadPluginLocales( $locale );
                     $cache->setData( $localeCode, DaoCacheConstants::CACHE_BLOG_LOCALES, $locale );
                 }
-				
-				Locales::_loadPluginLocales( $locale );
             }
                 
            $loadedLocales[$localeCode] = $locale;
@@ -148,15 +147,13 @@
             	$locale = $loadedLocales[$localeCode];
             } 
 			else {
-                
                 $cache =& CacheManager::getCache();
                 $locale = $cache->getData( $localeCode, DaoCacheConstants::CACHE_LOCALES );
                 if ( !$locale ) {
                     $locale = new Locale( $localeCode );
+					Locales::_loadPluginLocales( $locale );
                     $cache->setData( $localeCode, DaoCacheConstants::CACHE_LOCALES, $locale );
                 }
-
-				Locales::_loadPluginLocales( $locale );
             }
                 
            $loadedLocales[$localeCode] = $locale;

Modified: plog/trunk/class/template/menu/menu.class.php
===================================================================
--- plog/trunk/class/template/menu/menu.class.php	2008-02-25 04:06:23 UTC (rev 6187)
+++ plog/trunk/class/template/menu/menu.class.php	2008-02-25 05:12:10 UTC (rev 6188)
@@ -3,6 +3,8 @@
 	lt_include( PLOG_CLASS_PATH."class/xml/tree/Tree.php" );	
 	
 	define( "DEFAULT_MENU_FILE", "/admin/menus.xml" );
+	define( "MENU_CACHE_ENABLED", true );
+	define( "MENU_ITEMS", 'menu_items' );
 
     /**
      *  \ingroup Template
@@ -22,7 +24,8 @@
      */
     class Menu extends XML_Tree
     {
-    
+		var $_pluginMenuItems;
+
 		/**
 		 * constructor
 		 *
@@ -50,11 +53,21 @@
 		 */
 		function &getMenu( $menuFile = "" )
 		{
+			// Get cache manager
+			$cache =& CacheManager::getCache( MENU_CACHE_ENABLED );
+
 			static $instance;
-			
+
 			// create a new instance of the menu if it does not exist yet...
 			if( $instance == null )
-				$instance = new Menu( $menuFile );
+			{
+				$instance = $cache->getData( MENU_ITEMS, DaoCacheConstants::CACHE_MENU_ITEMS );
+				if( $instance == null )
+				{
+					$instance = new Menu( $menuFile );
+					$cache->setData( MENU_ITEMS, DaoCacheConstants::CACHE_MENU_ITEMS, $instance );
+				}
+			}
 				
 			// once we have it, return this instance
 			return $instance;
@@ -161,6 +174,13 @@
          */
         function addEntry( $entryPath, $entry, $entryOrder = -1 )
         {
+			if( !is_array( $this->_pluginMenuItems ) )
+				$this->_pluginMenuItems = array();
+
+			$menuItem = $entryPath.'/'.$entry->name;
+			if( $this->_pluginMenuItems[$menuItem] == 1 )
+				return true;
+
             // insertChild will return a reference to the node or PEAR_Error if there was
             // a problem
             $node = $this->insertChild( $this->_prepareEntryPath($entryPath), // path to the entry
@@ -195,9 +215,12 @@
 				}
 			}
 
-            
+			$this->_pluginMenuItems[$menuItem] = 1;
+			// Get cache manager
+			$cache =& CacheManager::getCache( MENU_CACHE_ENABLED );
+			$cache->setData( MENU_ITEMS, DaoCacheConstants::CACHE_MENU_ITEMS, $this );
+
             $ok = $this->isError( $node );
-            
             return $ok;
         }
         



More information about the pLog-svn mailing list