The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 861 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Caching for menu_data function?
#1
Since there seem to be a few submenu scripts around and menu_data being a useful function in general, how about implementing some sort of caching for it, so the files aren't loaded each time it is called?

It should hopefully be relatively simple to do, what I would do is: set a global variable for the data, use it if it is not NULL, if it is, then load the data into it (code untested), e.g.
Code:
$menu_data_cache = null;
function menu_data($id = null,$xml=false) {
        $menu_extract = '';
        global $PRETTYURLS;
        global $SITEURL;
        global $menu_data_cache;
        
        if($menu_data_cache == null) {
            $path = "data/pages";
            $dir_handle = @opendir($path) or die("Unable to open $path");
            $filenames = array();
            while ($filename = readdir($dir_handle)) {
                $filenames[] = $filename;
            }
            $count="0";
            $pagesArray = array();
            if (count($filenames) != 0) {
                foreach ($filenames as $file) {
                    if ($file == "." || $file == ".." || is_dir("data/pages/".$file) || $file == ".htaccess"  ) {
                        // not a page data file
                    } else {
                        $thisfile = @file_get_contents('data/pages/'.$file);
                        $data = simplexml_load_string($thisfile);
                        if ($data->private != 'Y') {
                            $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                            $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                            $pagesArray[$count]['menu'] = $data->menu;
                            $pagesArray[$count]['parent'] = $data->parent;
                            $pagesArray[$count]['title'] = $data->title;
                            $pagesArray[$count]['url'] = $data->url;
                            $pagesArray[$count]['private'] = $data->private;
                            $pagesArray[$count]['pubDate'] = $data->pubDate;
                            $count++;
                        }
                    }
                }
            }
            $menu_data_cache = $pagesArray;
        }
        else
        {
            $pagesArray = $menu_data_cache;
        }
.... rest of code ....

The same kind of thing could be done for other times when you are loading data from xml files.
-- Sam
Reply


Messages In This Thread
Caching for menu_data function? - by SamWM - 2010-05-15, 06:08:25



Users browsing this thread: 3 Guest(s)