Changeset 152 for trunk/bin


Ignore:
Timestamp:
Jun 7, 2006 5:35:16 AM (18 years ago)
Author:
scdev
Message:

Q - In the middle of working on the Prefs and Cache instantiation mode...can't decide to use singleton pattern or global vars. Updated ImageThumb? to allow filenames with path elements such as 01/23/4567_file.jpg.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/skel/admin.php

    r151 r152  
    1414
    1515require_once 'codebase/lib/PageNumbers.inc.php';
    16 require_once 'codebase/lib/SessionCache.inc.php';
     16require_once 'codebase/lib/Cache.inc.php';
    1717require_once 'codebase/lib/FormValidator.inc.php';
    1818require_once 'codebase/lib/SortOrder.inc.php';
     
    3333$fv = new FormValidator();
    3434
    35 $cache =& Cache::getInstance();
     35// Configure the prefs object.
     36$prefs =& Prefs::getInstance('%NAME_PLURAL%');
     37$prefs->setParam(array('persistent' => false));
     38
     39// Configure the cache object.
     40$cache =& Cache::getInstance('%NAME_PLURAL%');
     41$cache->setParam(array('enable' => true));
    3642
    3743%SORT_ORDER%
    3844
    39 // Instantiate page numbers. Total items are set and calculation is done in the getRecordList function.
     45// Instantiate page numbers. Total items are set and calculation is done in the getCachedList function.
    4046$page = new PageNumbers();
    4147$page->setPerPage(getFormData('per_page'), 100);
     
    5763
    5864if (getFormData('break_list_cache', false)) {
    59     // Break the cache because we are changing the list data.
    60     $cache->delete($_SERVER['PHP_SELF']);
     65    // Remove any stale cached list data.
     66    $cache->delete('list');
    6167}
    6268
     
    171177default :
    172178//     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_LIST, _("Permission to view %NAME_PLURAL% list denied."));
    173     $list =& getRecordList();
     179    $list =& getCachedList();
    174180    $main_template = '%ADMIN_LIST_TEMPLATE%';
    175181    break;
     
    250256    global $lock;
    251257    $db =& DB::getInstance();
    252     $cache =& Cache::getInstance();
     258    $cache =& Cache::getInstance('%NAME_PLURAL%');
    253259   
    254260    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
     
    257263    }
    258264
    259     // Break the cache because we are changing the list data.
    260     $cache->delete($_SERVER['PHP_SELF']);
     265    // Remove any stale cached list data.
     266    $cache->delete('list');
    261267
    262268    // Get the information for this object.
     
    285291    global $auth;
    286292    $db =& DB::getInstance();
    287     $cache =& Cache::getInstance();
     293    $cache =& Cache::getInstance('%NAME_PLURAL%');
    288294   
    289     // Break the cache because we are changing the list data.
    290     $cache->delete($_SERVER['PHP_SELF']);
     295    // Remove any stale cached list data.
     296    $cache->delete('list');
    291297
    292298%INSERT%
     
    306312    global $auth, $lock;
    307313    $app =& App::getInstance();
    308     $cache =& Cache::getInstance();
     314    $cache =& Cache::getInstance('%NAME_PLURAL%');
    309315   
    310316    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']);
     
    313319    }
    314320
    315     // Break the cache because we are changing the list data.
    316     $cache->delete($_SERVER['PHP_SELF']);
     321    // Remove any stale cached list data.
     322    $cache->delete('list');
    317323
    318324%UPDATE%
     
    328334}
    329335
    330 function &getRecordList()
     336function &getCachedList()
    331337{
    332338    global $page;
    333339    global $so;
    334     $db =& DB::getInstance();
    335     $prefs =& Prefs::getInstance();
    336     $cache =& Cache::getInstance();
    337    
     340    $db =& DB::getInstance();   
     341    $prefs =& Prefs::getInstance('%NAME_PLURAL%');
     342    $cache =& Cache::getInstance('%NAME_PLURAL%');
     343   
    338344    $where_clause = '';
    339345
     
    377383    ";
    378384
     385    // Use a cash hash to determine if the result-set has changed.
    379386    // A unique key for this query, with the total_items in case db records
    380387    // were added since the last cache. This identifies a unique set of
     
    383390    // without knowing the hash.
    384391    $cache_hash = md5($sql . '|' . $page->total_items);
    385     if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    386         $cache->delete($_SERVER['PHP_SELF']);
    387         $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    388     }
    389 
    390     if ($cache->exists($_SERVER['PHP_SELF'])) {
    391         // Get the cached results.
    392         $list = $cache->get($_SERVER['PHP_SELF']);
    393     } else {
    394         // If the list is not already cached, query now.
    395         $qid = $db->query($sql);
    396         // Fill an array with the items for this page.
    397         while ($row = mysql_fetch_assoc($qid)) {
    398             $list[] = $row;
    399         }
    400 
    401         if (isset($list) && !empty($list)) {
    402             // Cache the results.
    403             $cache->set($list, $_SERVER['PHP_SELF']);
    404         }
     392    if ($prefs->get('cache_hash') != $cache_hash) {
     393        $cache->delete('list');
     394        $prefs->set('cache_hash', $cache_hash);
     395    }
     396
     397    // First try to return from the cache.
     398    if ($cache->exists('list')) {
     399        return $cache->get('list');
     400    }
     401   
     402    // The list was not cached, so issue the real query.
     403    $qid = $db->query($sql);
     404    while ($row = mysql_fetch_assoc($qid)) {
     405        $list[] = $row;
     406    }
     407
     408    // Save this list into the cache.
     409    if (isset($list) && !empty($list)) {
     410        $cache->set('list', $list);
    405411    }
    406412
     
    411417{
    412418    $db =& DB::getInstance();
    413     $cache =& Cache::getInstance();
     419    $cache =& Cache::getInstance('%NAME_PLURAL%');
    414420   
    415421    if (!is_array($ranks)) {
     
    418424    }
    419425
    420     // Break the cache because we are changing the list data.
    421     $cache->delete($_SERVER['PHP_SELF']);
     426    // Remove any stale cached list data.
     427    $cache->delete('list');
    422428
    423429    // Count the ranks with invalid numbers
Note: See TracChangeset for help on using the changeset viewer.