function latestComments($all = true, $limit = 10) { $cacheName = cacheName('latest_comments_', array($all, $limit)); $comments = Cache::read($cacheName, 'core'); if (!empty($comments)) { return $comments; } $conditions = array(); if (!$all) { $conditions = array('Comment.active' => 1); } $comments = $this->find('all', array('conditions' => $conditions, 'limit' => $limit, 'order' => array('Comment.created' => 'DESC'))); Cache::write($cacheName, $comments, 'core'); return $comments; }
} // check for wrong filters if (implode('/', $filter) != $nofiltername && count($filter) != count($filters)) { // requested filters are wrong or not available $errormsg[] = 'InstantImage: requested filters are wrong or not available'; } // create empty image object $IMG = new InstantPicture($pref); $show = null; if ($debug == 2) { $IMG->error = $debugmsg; } elseif (implode('/', $filter) != $nofiltername && count($errormsg) == 0) { // default: create image $instant = true; // name of cache file $cachename = cacheName($picture, $filters, $cache, $cachefilterorder); // check for cache if ($cache != 'off' && is_file($pathToCache . $cachename)) { // image must be older than cache if (filemtime($picture) < filemtime($pathToCache . $cachename)) { $instant = false; $show = $pathToCache . $cachename; } } if ($instant === true) { $IMG->apply($picture, $filters); if ($cache != 'off' && count($errormsg) == 0) { $IMG->imageSaveToFile($pathToCache . $cachename); } } } else {
/** * Get the average views in total or per model * * @param string $model the model to check against * * @return int the average views of the selected range. */ public function getAverage($model = null) { $this->virtualFields['views'] = 'COUNT(' . $this->alias . '.id)'; $conditions = $group = array(); if ($model) { $conditions[$this->alias . '.model'] = (string) $model; $group[] = $this->alias . '.foreign_key'; } $cacheName = cacheName('view_average', array($conditions, $group)); $data = Cache::read($cacheName, 'view_counts'); if ($data !== false) { return $data; } $data = $this->find('all', array('fields' => array('views'), 'conditions' => $conditions, 'group' => $group)); if (!empty($data)) { $data = Set::extract('/' . $this->alias . '/views', $data); $data = round(array_sum($data) / count($data)); Cache::write($cacheName, $data, 'view_counts'); } return $data; }
/** * generate cache names for the attachment. there is the info and the * main data file with appropriate prefixes * * @param <type> $attachment * @param <type> $type * @return <type> */ private function __getCachedName($attachment, $type = 'info') { return cacheName($type, array('message_id' => $attachment['message_id'], 'name' => $attachment['name'], 'filename' => $attachment['filename'])); }