| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListInterfaceCachingEngine.php');
|
| 5 |
/**
|
| 6 |
* The caching engine uses the standard drupal cache functions to store loaded nodes for a short time. This keeps down the
|
| 7 |
* possibly complicated load-times that happen when a node is loaded by passing it around through nodeapi.
|
| 8 |
*
|
| 9 |
* We save the cached data in cache_block, because it will be invalidated when a node is updated or inserted.
|
| 10 |
*/
|
| 11 |
class SimpleListCachingEngine implements SimpleListInterfaceCachingEngine {
|
| 12 |
public function fetch_node($nid) {
|
| 13 |
$cache_data = cache_get($this->get_node_cache_id($nid), 'cache_block');
|
| 14 |
//drupal_set_message('cache:'. dprint_r($cache_data, true));
|
| 15 |
if ($cache_data) {
|
| 16 |
return $cache_data->data;
|
| 17 |
}
|
| 18 |
else {
|
| 19 |
$node = node_load($nid);
|
| 20 |
cache_set($this->get_node_cache_id($nid), $node, 'cache_block', CACHE_TEMPORARY);
|
| 21 |
return $node;
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
public function get_node_cache_id($nid) {
|
| 26 |
global $user;
|
| 27 |
return 'node_'. implode(',', array_keys($user->roles)) .'_'. $nid;
|
| 28 |
}
|
| 29 |
}
|
| 30 |
?>
|