static function getAll() { $userCounts = self::cacheGet('sitemap:user:counts'); if ($userCounts === false) { $suc = new Sitemap_user_count(); $suc->orderBy('registration_date DESC'); // Fetch the first one to check up-to-date-itude $n = $suc->find(true); $today = self::today(); $userCounts = array(); if (!$n) { // No counts saved yet $userCounts = self::initializeCounts(); } else { if ($suc->registration_date < $today) { // There are counts but not up to today $userCounts = self::fillInCounts($suc->registration_date); } else { if ($suc->registration_date == $today) { // Refresh today's $userCounts[$today] = self::updateToday(); } } } // starts with second-to-last date while ($suc->fetch()) { $userCounts[$suc->registration_date] = $suc->user_count; } // Cache user counts for 4 hours. self::cacheSet('sitemap:user:counts', $userCounts, null, time() + 4 * 60 * 60); } return $userCounts; }