Friday, December 16, 2011

Custom Caching code for Repeatedly used code in Drupal

global $contentType_cache;
   
    if (!isset($contentType_cache)) {
        $cache_content = cache_get("CACHE_TBL_CONTENTTYPE");
        $cache_content = $cache_content->data;
        if (!isset($cache_content)) {       
            // Load the complete list of the thumbnail
            $result = db_query("SELECT type, name FROM {node_type}");
            $records = array();
           
            while ($record = db_fetch_object($result)) {
                $records[$record->type] = $record;
            }
            cache_set("CACHE_TBL_CONTENTTYPE", $records);
            $contentType_cache= $records;
        } else {
            $contentType_cache= $cache_content;
        }
    }

No comments:

Post a Comment

Followers