/** * Ustawienie menu */ private function initMenu() { $menu = Cache::read('menu-' . $this->userRole); if (!isset($menu) || $menu === false) { // Pobranie menu z configa Configure::load('Admin.app_menu', 'default'); $menuConfig = Configure::read('menu'); $that = $this; $generateMenu = function ($array) use($that, &$generateMenu) { $menu = array(); foreach ($array as $key => $item) { $link = $item['link']; // czy ma dostep if (!$link || $that->permission->check($link['controller'], $link['action'])) { $childs = []; if (isset($item['childs']) && !empty($item['childs'])) { $childs = $generateMenu($item['childs']); $item['childs'] = $childs; } // Nie dodaje pustych elementów do menu bez linku if (count($childs) == 0 && !$link) { continue; } $menu[$key] = $item; } } return $menu; }; $menu = $generateMenu($menuConfig); Cache::write('menu-' . $this->userRole, $menu); } $this->set('params', $this->request->params); $this->set('menu', $menu); }
/** * testTranslationCaching method * * @return void */ public function testTranslationCaching() { $this->skipIf(!Cache::engine('_cake_core_'), 'Missing _cake_core_ cache config, cannot test caching.'); Configure::write('Config.language', 'cache_test_po'); // reset internally stored entries I18n::clear(); Cache::clear(false, '_cake_core_'); $lang = Configure::read('Config.language'); // make some calls to translate using different domains $this->assertEquals('Dom 1 Foo', I18n::translate('dom1.foo', false, 'dom1')); $this->assertEquals('Dom 1 Bar', I18n::translate('dom1.bar', false, 'dom1')); $domains = I18n::domains(); $this->assertEquals('Dom 1 Foo', $domains['dom1']['cache_test_po']['LC_MESSAGES']['dom1.foo']); // reset internally stored entries I18n::clear(); // now only dom1 should be in cache $cachedDom1 = Cache::read('dom1_' . $lang, '_cake_core_'); $this->assertEquals('Dom 1 Foo', $cachedDom1['LC_MESSAGES']['dom1.foo']); $this->assertEquals('Dom 1 Bar', $cachedDom1['LC_MESSAGES']['dom1.bar']); // dom2 not in cache $this->assertFalse(Cache::read('dom2_' . $lang, '_cake_core_')); // translate a item of dom2 (adds dom2 to cache) $this->assertEquals('Dom 2 Foo', I18n::translate('dom2.foo', false, 'dom2')); // verify dom2 was cached through manual read from cache $cachedDom2 = Cache::read('dom2_' . $lang, '_cake_core_'); $this->assertEquals('Dom 2 Foo', $cachedDom2['LC_MESSAGES']['dom2.foo']); $this->assertEquals('Dom 2 Bar', $cachedDom2['LC_MESSAGES']['dom2.bar']); // modify cache entry manually to verify that dom1 entries now will be read from cache $cachedDom1['LC_MESSAGES']['dom1.foo'] = 'FOO'; Cache::write('dom1_' . $lang, $cachedDom1, '_cake_core_'); $this->assertEquals('FOO', I18n::translate('dom1.foo', false, 'dom1')); }
/** * Get option by key * * @param string $key Option key * @return mixed|null */ public static function get($key) { if (!($options = Cache::read(self::$_config['cache_name']))) { $options = self::getAll(); } return array_key_exists($key, $options) ? $options[$key] : null; }
/** * Establishes a connection to the salesforce server * * @param array $config configuration to be used for creating connection * @return bool true on success */ protected function _connect(array $config) { $this->config = $config; if (empty($this->config['my_wsdl'])) { throw new \ErrorException("A WSDL needs to be provided"); } else { $wsdl = CONFIG . DS . $this->config['my_wsdl']; } $mySforceConnection = new \SforceEnterpriseClient(); $mySoapClient = $mySforceConnection->createConnection($wsdl); $sflogin = (array) Cache::read('salesforce_login', 'salesforce'); if (!empty($sflogin['sessionId'])) { $mySforceConnection->setSessionHeader($sflogin['sessionId']); $mySforceConnection->setEndPoint($sflogin['serverUrl']); } else { try { $mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']); $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl); Cache::write('salesforce_login', $sflogin, 'salesforce'); } catch (Exception $e) { $this->log("Error logging into salesforce - Salesforce down?"); $this->log("Username: "******"Password: " . $this->config['password']); } } $this->client = $mySforceConnection; $this->connected = true; return $this->connected; }
public function testInIndexBehavior() { $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestInRelatedIndexBehavior'); $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestHasRelatedBehavior'); /*$testEntity = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']); $this->Articles->save($testEntity);*/ //<editor-fold desc="Should get two related"> $firstArticle = $this->Articles->get(1, ['getRelated' => true]); $this->assertCount(2, $firstArticle->related); //</editor-fold> //<editor-fold desc="Should save only one"> $firstArticle = $this->Articles->patchEntity($firstArticle, ['related-articles' => [['id' => 3, '_joinData' => ['source_table_name' => 'articles', 'target_table_name' => 'articles']]]]); $this->Articles->save($firstArticle); $firstArticle = $this->Articles->get(1, ['getRelated' => true]); $this->assertCount(1, $firstArticle->related); //</editor-fold> //<editor-fold desc="Test if cache works"> $newArticle = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']); $this->Articles->save($newArticle); $attachedTables = Cache::read('Related.attachedTables'); $indexedTables = Cache::read('Related.indexedTables'); $this->assertCount(1, $attachedTables); $this->assertEquals('articles', $attachedTables[0]); $this->assertCount(5, $indexedTables['Articles']); $this->assertEquals('Test title five', $indexedTables['Articles'][5]); $this->Articles->delete($this->Articles->get(3)); $indexedTables = Cache::read('Related.indexedTables'); $this->assertCount(4, $indexedTables['Articles']); //</editor-fold> }
/** * Prepares some variables used in "default.ctp" layout, such as skin color to use, * pending comments counter, etc. * * @return array Associative array */ function backendLayoutVars() { $layoutOptions = []; $skin = theme()->settings('skin'); $boxClass = 'success'; $pendingComments = Cache::read('pending_comments', 'pending_comments'); if ($pendingComments === false) { $pendingComments = TableRegistry::get('Comment.Comments')->find()->where(['Comments.status' => 'pending', 'Comments.table_alias' => 'contents'])->count(); Cache::write('pending_comments', $pendingComments, 'pending_comments'); } $pendingComments = !$pendingComments ? '' : $pendingComments; if (strpos($skin, 'blue') !== false || strpos($skin, 'black') !== false) { $boxClass = 'info'; } elseif (strpos($skin, 'green') !== false) { $boxClass = 'success'; } elseif (strpos($skin, 'red') !== false || strpos($skin, 'purple') !== false) { $boxClass = 'danger'; } elseif (strpos($skin, 'yellow') !== false) { $boxClass = 'warning'; } if (theme()->settings('fixed_layout')) { $layoutOptions[] = 'fixed'; } if (theme()->settings('boxed_layout')) { $layoutOptions[] = 'layout-boxed'; } if (theme()->settings('collapsed_sidebar')) { $layoutOptions[] = 'sidebar-collapse'; } return compact('skin', 'layoutOptions', 'boxClass', 'pendingComments'); }
public function read($id) { $result = Cache::read($id, $this->cacheKey); if ($result) { return $result; } return parent::read($id); }
/** * Method used to read from a cache session. * * @param string $id The key of the value to read * @return string The value of the key or empty if it does not exist */ public function read($id) { $value = Cache::read($id, $this->_options['config']); if (empty($value)) { return ''; } return $value; }
/** * @return mixed */ protected function _getIndexedTables() { if (($indexed_tables = Cache::read('Related.indexedTables')) === false) { $InRelatedIndexBehavior = new InRelatedIndexBehavior(TableRegistry::get('')); $InRelatedIndexBehavior->refreshCache(); $indexed_tables = Cache::read('Related.indexedTables'); } return $indexed_tables; }
public function index() { if (($books = Cache::read('exlibrisBooksIndex')) === false) { $books = $this->Books->find('all')->contain('Publishers')->all(); Cache::write('exlibrisBooksIndex', $books); } $this->set('books', $books); $this->set('_serialize', ['books']); }
/** * Tests that schema metadata is cached * * @return void */ public function testDescribeCache() { $schema = $this->connection->schemaCollection(); $table = $this->connection->schemaCollection()->describe('users'); Cache::delete('test_users', '_cake_model_'); $schema->cacheMetadata(true); $result = $schema->describe('users'); $this->assertEquals($table, $result); $result = Cache::read('test_users', '_cake_model_'); $this->assertEquals($table, $result); }
/** * Internal method to get the latest photos * @param int $limit Limit * @return array * @uses MeInstagram\Utility\Instagram::recent() */ protected function _latest($limit = 15) { //Tries to get data from the cache $photos = Cache::read($cache = sprintf('latest_%s', $limit), 'instagram'); //If the data are not available from the cache if (empty($photos)) { list($photos) = Instagram::recent(null, $limit); Cache::write($cache, $photos, 'instagram'); } return $photos; }
public function view($slug) { $pagina = Cache::read('pagina_view_' . $slug); if ($pagina === false) { $pagina = $this->Paginas->getPaginaBySlug($slug); Cache::write('pagina_view_' . $slug, $pagina); } if (!$pagina) { throw new NotFoundException(); } $this->set(compact('pagina')); }
/** * Tests that schema metadata is cached * * @return void */ public function testDescribeCache() { $schema = $this->connection->methodSchemaCollection(); $method = $this->connection->methodSchemaCollection()->describe('CALC.SUM'); Cache::delete('test_CALC_SUM', '_cake_method_'); $this->connection->cacheMetadata(true); $schema = $this->connection->methodSchemaCollection(); $result = $schema->describe('CALC.SUM'); $this->assertEquals($method, $result); $result = Cache::read('test_CALC_SUM', '_cake_method_'); $this->assertEquals($method, $result); }
/** * Creates a new Query for this repository and applies some defaults based * on the type of search that was selected * @param string $type The type of query to perform * @param array|ArrayAccess $options An array that will be passed to * Query::applyOptions() * @return Cake\ORM\Query The query builder * @uses setNextToBePublished() * @uses $cache */ public function find($type = 'all', $options = []) { //Gets from cache the timestamp of the next record to be published $next = Cache::read('next_to_be_published', $this->cache); //If the cache is not valid, it empties the cache if ($next && time() >= $next) { Cache::clear(false, $this->cache); //Sets the next record to be published $this->setNextToBePublished(); } return parent::find($type, $options); }
/** * Write user failed login. * * @param Controller $controller * @return void */ protected function _writeFailedLogin(Controller $controller) { $cacheConfig = 'auth'; if ($controller->request->param('prefix') == 'admin') { $cacheConfig .= '_admin'; } $cacheName = 'failed_' . $controller->request->data('username'); $cacheValue = (int) Cache::read($cacheName, $cacheConfig); $cookieVal = $controller->Cookie->read('fail.auth'); $controller->Cookie->config(['expires' => '+300 seconds']); $controller->Cookie->write('fail.auth', (int) $cookieVal + 1); Cache::write($cacheName, (int) $cacheValue + 1, $cacheConfig); }
/** * Renders the login form. * * @return \Cake\Network\Response|null */ public function login() { $this->loadModel('User.Users'); $this->viewBuilder()->layout('login'); if ($this->request->is('post')) { $loginBlocking = plugin('User')->settings('failed_login_attempts') && plugin('User')->settings('failed_login_attempts_block_seconds'); $continue = true; if ($loginBlocking) { Cache::config('users_login', ['duration' => '+' . plugin('User')->settings('failed_login_attempts_block_seconds') . ' seconds', 'path' => CACHE, 'engine' => 'File', 'prefix' => 'qa_', 'groups' => ['acl']]); $cacheName = 'login_failed_' . env('REMOTE_ADDR'); $cache = Cache::read($cacheName, 'users_login'); if ($cache && $cache['attempts'] >= plugin('User')->settings('failed_login_attempts')) { $blockTime = (int) plugin('User')->settings('failed_login_attempts_block_seconds'); $this->Flash->warning(__d('user', 'You have reached the maximum number of login attempts. Try again in {0} minutes.', $blockTime / 60)); $continue = false; } } if ($continue) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); if (!empty($user['id'])) { try { $user = $this->Users->get($user['id']); if ($user) { $this->Users->touch($user, 'Users.login'); $this->Users->save($user); } } catch (\Exception $e) { // invalid user } } return $this->redirect($this->Auth->redirectUrl()); } else { if ($loginBlocking && isset($cache) && isset($cacheName)) { $cacheStruct = ['attempts' => 0, 'last_attempt' => 0, 'ip' => '', 'request_log' => []]; $cache = array_merge($cacheStruct, $cache); $cache['attempts'] += 1; $cache['last_attempt'] = time(); $cache['ip'] = env('REMOTE_ADDR'); $cache['request_log'][] = ['data' => $this->request->data, 'time' => time()]; Cache::write($cacheName, $cache, 'users_login'); } $this->Flash->danger(__d('user', 'Username or password is incorrect.')); } } } $user = $this->Users->newEntity(); $this->title(__d('user', 'Login')); $this->set(compact('user')); }
protected function _tableChanged($event, $entity, $options) { $modelName = $this->_table->alias(); if (($indexedTables = Cache::read('Related.indexedTables')) === false) { //Nepodařilo se načíst z cache $this->refreshCache(); } else { //Načteno z cache $indexedTables[$modelName] = $this->_table->find('list', ['only_active' => true])->toArray(); Cache::write('Related.indexedTables', $indexedTables); } echo ""; return true; }
public function beforeDispatch(Event $event, Request $request, Response $response) { if (Configure::read('debug')) { return; } $cacheKey = $this->_getCacheKey($request); if ($cacheKey !== false) { $content = Cache::read($cacheKey, 'wasabi/cms/pages'); if ($content !== false) { $response->body($content); $event->result = $response; } } }
/** * {@inheritDoc} * */ public function describe($name, array $options = []) { $options += ['forceRefresh' => false]; $cacheConfig = $this->cacheMetadata(); $cacheKey = $this->cacheKey($name); if (!empty($cacheConfig) && !$options['forceRefresh']) { $cached = Cache::read($cacheKey, $cacheConfig); if ($cached !== false) { return $cached; } } $table = parent::describe($name, $options); if (!empty($cacheConfig)) { Cache::write($cacheKey, $table, $cacheConfig); } return $table; }
/** * Returns a application access token. * * @return string|bool The access token or false in case of a failure */ public function accessToken() { $cacheKey = 'twitter-' . $this->config('name') . '-token'; if (Cache::read($cacheKey) !== false) { return Cache::read($cacheKey); } $bearerToken = $this->bearerToken(); if (!$bearerToken) { return false; } $client = new Client(['headers' => ['Authorization' => 'Basic ' . $bearerToken], 'host' => 'api.twitter.com', 'scheme' => 'https']); $response = $client->post('/oauth2/token', ['grant_type' => 'client_credentials']); if (!$response->isOk() || !$response->json['token_type']) { return false; } Cache::write($cacheKey, $response->json['access_token']); return $response->json['access_token']; }
/** * Returns a list of Controller names found in /src/Controller/Api. * * @return array List holding sorted Controller names */ public static function getApiControllers() { $cached = Cache::read('api_controllers'); if ($cached) { return $cached; } $dir = new Folder(APP . 'Controller' . DS . Inflector::camelize(Configure::read('App++.Api.prefix'))); $controllerFiles = $dir->find('.*Controller\\.php'); if (!$controllerFiles) { return false; } $result = []; foreach ($controllerFiles as $controllerFile) { $result[] = substr($controllerFile, 0, strlen($controllerFile) - 14); } sort($result); Cache::write('api_controllers', $result); return $result; }
/** * Perform cache-aware, Geshi-aware processing of markdown text * * Pass your markdown text and get the html for output. * * If the GeshiHelper has been installed, properly delimeted source code * in your markdown will be nicely highlighted. * * To use caching of the output you'll need to pass an object instead of * a text string. The object must implement the MarkdownInterface. * * To gain greater control over the geshi output you'll need to pass an object * that implements the GeshiInterface * * @param object|string $source Text in markdown format or an object * @return string */ public function transform($source) { if (is_object($source)) { if (!$source instanceof MarkdownInterface) { throw new \BadFunctionCallException('CakeMarkdown::transform() argument must be an object that implements MardownInterface or a string'); } if ($source->markdownCaching()) { $output = Cache::read($source->markdownCacheKey($this), $source->markdownCacheConfig($this)); if ($output) { return $output; } } } $output = $this->chooseTransform($source); if (is_object($source) && $source->markdownCaching()) { Cache::write($source->markdownCacheKey($this), $output, $source->markdownCacheConfig($this)); } return $output; }
protected function _icons() { $useCache = true; if (!empty($this->request->params['named']['reset'])) { $useCache = false; } if ($useCache && ($iconNames = Cache::read('country_icon_names')) !== false) { $this->Flash->info('Cache Used'); return $iconNames; } $handle = new Folder($this->imageFolder); $icons = $handle->read(true, true); $iconNames = []; foreach ($icons[1] as $icon) { # only use files (not folders) $iconNames[] = strtoupper(extractPathInfo('filename', $icon)); } Cache::write('country_icon_names', $iconNames); return $iconNames; }
public static function loadListeners() { $eventManager = EventManager::instance(); $cached = Cache::read('EventHandlers', 'default'); if ($cached === false) { $eventHandlers = Configure::read('EventHandlers'); $validKeys = array('eventKey' => null, 'options' => array()); $cached = array(); if (!empty($eventHandlers) && is_array($eventHandlers)) { foreach ($eventHandlers as $eventHandler => $eventOptions) { $eventKey = null; if (is_numeric($eventHandler)) { $eventHandler = $eventOptions; $eventOptions = array(); } list($plugin, $class) = pluginSplit($eventHandler); if (!empty($eventOptions)) { extract(array_intersect_key($eventOptions, $validKeys)); } if (isset($eventOptions['options']['className'])) { list($plugin, $class) = pluginSplit($eventOptions['options']['className']); } if (class_exists('\\' . $plugin . '\\Event\\' . $class)) { $cached[] = compact('plugin', 'class', 'eventKey', 'eventOptions'); } else { Log::error(__d('croogo', 'EventHandler %s not found in plugin %s', $class, $plugin)); } } Cache::write('EventHandlers', $cached, 'default'); } } foreach ($cached as $cache) { extract($cache); if (Plugin::loaded($plugin)) { $settings = isset($eventOptions['options']) ? $eventOptions['options'] : array(); $namespace = '\\' . $plugin . '\\Event\\' . $class; $listener = new $namespace($settings); $eventManager->on($listener, $eventKey, $eventOptions); } } }
/** * Authorizes current logged in user, if user belongs to the "administrator" * he/she is automatically authorized. * * @param array $user Active user data * @param \Cake\Network\Request $request Request instance * @return bool True if user is can access this request */ public function authorize($user, Request $request) { if ($request->is('userAdmin')) { return true; } $user = user(); $path = $this->requestPath($request); $cacheKey = 'permissions_' . intval($user->id); $permissions = Cache::read($cacheKey, 'permissions'); if ($permissions === false) { $permissions = []; Cache::write($cacheKey, [], 'permissions'); } if (!isset($permissions[$path])) { $allowed = $user->isAllowed($path); $permissions[$path] = $allowed; Cache::write($cacheKey, $permissions, 'permissions'); } else { $allowed = $permissions[$path]; } return $allowed; }
public function appLoad($userID) { if ($userID !== null) { $notificationTable = TableRegistry::get('Notifications'); $controller = $this->_registry->getController(); $notificationEnts = $notificationTable->find('unread')->where(['user_id' => $userID]); $notificationCount = $notificationEnts->count(); if (isset($notificationCount) && $notificationCount > 0) { $unreadNotifications = true; } else { $unreadNotifications = false; } $controller->set(compact('unreadNotifications')); $userAppProgress = 'appProgress' . $userID; $appProgress = Cache::read($userAppProgress); if (empty($appProgress)) { //$this->loadComponent('Progress'); //$this->Progress->cacheApps($userID); } //$controller->set(compact('appProgress')); } }
protected function initData() { $menus = \Cake\Cache\Cache::read('admin_menus'); if ($menus === false) { $Menu = \Cake\ORM\TableRegistry::get('cwp_menu'); $menus = $Menu->find()->hydrate(false)->where('status = 1')->orderDesc('rank')->toArray(); $menus = \Admin\Utils\Util::getMenu($menus); \Cake\Cache\Cache::write('admin_menus', $menus); } $this->_menus = $menus; $controller = strtolower($this->request->param('controller')); $action = strtolower($this->request->param('action')); $url = '/admin/' . $controller . '/' . $action; $this->_url = $url; $active = null; foreach ($menus as $value) { if (isset($value['child'])) { foreach ($value['child'] as $sub_menu) { if ($sub_menu['node'] == $url) { $this->_pageTitle = $sub_menu['name']; $this->_breadFirst = ['name' => $value['name'], 'node' => $value['node']]; $this->_breadSecond = ['name' => $sub_menu['name'], 'node' => $sub_menu['node']]; break; } if (isset($sub_menu['child'])) { foreach ($sub_menu['child'] as $v) { if ($v['node'] == $url) { $active = $sub_menu['node']; $this->_active = $active; $this->_pageTitle = $v['name']; $this->_breadFirst = ['name' => $value['name'], 'node' => $value['node']]; $this->_breadSecond = ['name' => $sub_menu['name'], 'node' => $sub_menu['node']]; } } } } } } }
/** * @param ComponentRegistry $registry The controller for this request. * @param array $config An array of config. This class does not use any config. */ public function __construct(ComponentRegistry $registry, array $config = []) { parent::__construct($registry, $config); if (!file_exists(CONFIG . $this->config('hierarchyFile'))) { throw new Exception(sprintf("Provided hierarchy config file %s doesn't exist.", $this->config('hierarchyFile'))); } if (!file_exists(CONFIG . $this->config('aclFile'))) { throw new Exception(sprintf("Provided ACL config file %s doesn't exist.", $this->config('aclFile'))); } // caching $hierarchyModified = filemtime(CONFIG . $this->config('hierarchyFile')); $aclModified = filemtime(CONFIG . $this->config('aclFile')); $lastModified = $hierarchyModified > $aclModified ? $hierarchyModified : $aclModified; if (Cache::read('hierarchy_auth_build_time') < $lastModified) { $this->_hierarchy = $this->_getHierarchy(); $this->_acl = $this->_getAcl(); Cache::write('hierarchy_auth_cache', ['acl' => $this->_acl, 'hierarchy' => $this->_hierarchy]); Cache::write('hierarchy_auth_build_time', time()); } else { $cache = Cache::read('hierarchy_auth_cache'); $this->_hierarchy = $cache['hierarchy']; $this->_acl = $cache['acl']; } }
public function stats() { $filter = $this->_getTimeFilter(); $relatedEntries = array(); $filter_string = $this->request->query('filter'); if (!$filter_string) { $filter_string = "all_time"; } $entriesWithCount = array(); //Cache::clear(false); foreach (TableRegistry::get('Incidents')->summarizableFields as $field) { if (($entriesWithCount = Cache::read($field . '_' . $filter_string)) === false) { $entriesWithCount = TableRegistry::get('Reports')->getRelatedByField($field, 25, false, false, $filter["limit"]); $entriesWithCount = json_encode($entriesWithCount); Cache::write($field . '_' . $filter_string, $entriesWithCount); } $relatedEntries[$field] = json_decode($entriesWithCount, TRUE); } $this->set("related_entries", $relatedEntries); $this->set('columns', TableRegistry::get('Incidents')->summarizableFields); $this->set('filter_times', TableRegistry::get('Incidents')->filterTimes); $this->set('selected_filter', $this->request->query('filter')); $query = array('group' => 'grouped_by', 'order' => 'Incidents.created'); if (isset($filter["limit"])) { $query["conditions"] = array('Incidents.created >=' => $filter["limit"]); } TableRegistry::get('Incidents')->recursive = -1; $downloadStats = array(); if (($downloadStats = Cache::read('downloadStats_' . $filter_string)) === false) { $downloadStats = TableRegistry::get('Incidents')->find('all', $query); $downloadStats->select(['grouped_by' => $filter["group"], 'date' => "DATE_FORMAT(Incidents.created, '%a %b %d %Y %T')", 'count' => $downloadStats->func()->count('*')]); $downloadStats = json_encode($downloadStats->toArray()); Cache::write('downloadStats_' . $filter_string, $downloadStats); } $this->set('download_stats', json_decode($downloadStats, TRUE)); }