static function load($id, $fields) { $mem = "user:{$id}"; if ($user = memget($mem)) { return $user; } $user = Model::factory(get_called_class())->where('id', $id)->find_one(); if ($user) { memset($mem, $user); } return $user; }
function ga_get_profile_data($profile_id, $start, $end, $debug = false) { global $gaservice; $cache_key = md5("ga_get_profile_data({$profile_id},{$start},{$end})"); if (!$debug && ($cache = memget($cache_key))) { return $cache; } $response = $gaservice->data_ga->get('ga:' . $profile_id, $start, $end, 'ga:pageviews,ga:visitors,ga:organicSearches', array('dimensions' => 'ga:socialNetwork,ga:source')); $data = array('start' => $response['query']['start-date'], 'end' => $response['query']['end-date'], 'pageviews' => $response['totalsForAllResults']['ga:pageviews'], 'visitors' => $response['totalsForAllResults']['ga:visitors'], 'pageviewbysource' => array('facebook' => ga_sum_dimension($response, 0, 'Facebook', 1), 'twitter' => ga_sum_dimension($response, 0, 'Twitter', 1), 'pinterest' => ga_sum_dimension($response, 0, 'Pinterest', 1), 'google' => ga_sum_dimension($response, 1, 'google%', 0))); $data['cached'] = time(); memset($cache_key, $data, 300); if ($debug) { $data['response'] = $response; } return $data; }