- Timestamp:
- Jun 7, 2006 5:35:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/module_maker/skel/admin.php
r151 r152 14 14 15 15 require_once 'codebase/lib/PageNumbers.inc.php'; 16 require_once 'codebase/lib/ SessionCache.inc.php';16 require_once 'codebase/lib/Cache.inc.php'; 17 17 require_once 'codebase/lib/FormValidator.inc.php'; 18 18 require_once 'codebase/lib/SortOrder.inc.php'; … … 33 33 $fv = new FormValidator(); 34 34 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)); 36 42 37 43 %SORT_ORDER% 38 44 39 // Instantiate page numbers. Total items are set and calculation is done in the get RecordList function.45 // Instantiate page numbers. Total items are set and calculation is done in the getCachedList function. 40 46 $page = new PageNumbers(); 41 47 $page->setPerPage(getFormData('per_page'), 100); … … 57 63 58 64 if (getFormData('break_list_cache', false)) { 59 // Break the cache because we are changing thelist data.60 $cache->delete( $_SERVER['PHP_SELF']);65 // Remove any stale cached list data. 66 $cache->delete('list'); 61 67 } 62 68 … … 171 177 default : 172 178 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_LIST, _("Permission to view %NAME_PLURAL% list denied.")); 173 $list =& get RecordList();179 $list =& getCachedList(); 174 180 $main_template = '%ADMIN_LIST_TEMPLATE%'; 175 181 break; … … 250 256 global $lock; 251 257 $db =& DB::getInstance(); 252 $cache =& Cache::getInstance( );258 $cache =& Cache::getInstance('%NAME_PLURAL%'); 253 259 254 260 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id); … … 257 263 } 258 264 259 // Break the cache because we are changing thelist data.260 $cache->delete( $_SERVER['PHP_SELF']);265 // Remove any stale cached list data. 266 $cache->delete('list'); 261 267 262 268 // Get the information for this object. … … 285 291 global $auth; 286 292 $db =& DB::getInstance(); 287 $cache =& Cache::getInstance( );293 $cache =& Cache::getInstance('%NAME_PLURAL%'); 288 294 289 // Break the cache because we are changing thelist data.290 $cache->delete( $_SERVER['PHP_SELF']);295 // Remove any stale cached list data. 296 $cache->delete('list'); 291 297 292 298 %INSERT% … … 306 312 global $auth, $lock; 307 313 $app =& App::getInstance(); 308 $cache =& Cache::getInstance( );314 $cache =& Cache::getInstance('%NAME_PLURAL%'); 309 315 310 316 $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']); … … 313 319 } 314 320 315 // Break the cache because we are changing thelist data.316 $cache->delete( $_SERVER['PHP_SELF']);321 // Remove any stale cached list data. 322 $cache->delete('list'); 317 323 318 324 %UPDATE% … … 328 334 } 329 335 330 function &get RecordList()336 function &getCachedList() 331 337 { 332 338 global $page; 333 339 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 338 344 $where_clause = ''; 339 345 … … 377 383 "; 378 384 385 // Use a cash hash to determine if the result-set has changed. 379 386 // A unique key for this query, with the total_items in case db records 380 387 // were added since the last cache. This identifies a unique set of … … 383 390 // without knowing the hash. 384 391 $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); 405 411 } 406 412 … … 411 417 { 412 418 $db =& DB::getInstance(); 413 $cache =& Cache::getInstance( );419 $cache =& Cache::getInstance('%NAME_PLURAL%'); 414 420 415 421 if (!is_array($ranks)) { … … 418 424 } 419 425 420 // Break the cache because we are changing thelist data.421 $cache->delete( $_SERVER['PHP_SELF']);426 // Remove any stale cached list data. 427 $cache->delete('list'); 422 428 423 429 // Count the ranks with invalid numbers
Note: See TracChangeset
for help on using the changeset viewer.