Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Test module for Drupal which get a page.
- */
- /**
- * Implements hook_menu().
- */
- function pv_test_cache_menu() {
- $items = array();
- $items['testcache'] = array(
- 'title' => 'Test cache',
- 'description' => 'Test Cache',
- 'page callback' => 'pv_test_cache_content',
- 'access callback' => TRUE,
- 'type' => MENU_NORMAL_ITEM,
- 'menu_name' => 'main-menu',
- );
- return $items;
- }
- /**
- * Provide data to template.
- */
- function pv_test_cache_content() {
- $content = "<h1> User First Name: " . pv_test_cache_check_cache() . "</h1>";
- return $content;
- }
- /**
- * Function which look at cache.
- */
- function pv_test_cache_check_cache() {
- $user_first_name_from_cache = cache_get('pv_test_cache');
- $user_first_name_from_db = get_user_first_name();
- if ($user_first_name_from_cache && $user_first_name_from_cache->data == $user_first_name_from_db) {
- return $user_first_name_from_cache->data;
- }
- else {
- cache_clear_all('pv_test_cache', 'cache', TRUE);
- cache_set('pv_test_cache', $user_first_name_from_db, 'cache');
- return $user_first_name_from_db;
- }
- }
- /**
- * Function which take User First Name from db.
- */
- function get_user_first_name() {
- global $user;
- $query = db_select('field_data_field_account_first_name', 'fdfafn');
- $query->fields('fdfafn', array('field_account_first_name_value'));
- $query->condition('fdfafn.entity_id', $user->uid);
- $first_name = $query->execute()->fetchAll();
- return $first_name[0]->field_account_first_name_value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement