/** * Prepare cached data for System usage * * * @access public * * @param bool $forceFlush ,default is bool false * @return array cached System data serialized */ public function prepareCachedSystemData($forceFlush = false) { if ($forceFlush === false) { $cachedSystemDataKeys = array(self::SETTINGS_KEY); $existingCachedSystemDataKeys = $this->cache->cacheAdapter->hasItems($cachedSystemDataKeys); } if ($forceFlush === true || $forceFlush === false && count($existingCachedSystemDataKeys) !== count($cachedSystemDataKeys)) { $settings = $this->query->findAll('System\\Entity\\Setting'); $settingsArray = array(); foreach ($settings as $setting) { $settingsArray[$setting->name] = $setting->value; } $items = array(self::SETTINGS_KEY => serialize($settingsArray)); $this->cache->setItems($items); } else { $items = $this->getCachedSystemData(); $items = array(self::SETTINGS_KEY => serialize($items[self::SETTINGS_KEY])); } return $items; }
/** * Prepare cached data for CMS usage * * * @access public * * @param bool $forceFlush ,default is bool false * @return array cached CMS data serialized */ public function prepareCachedCMSData($forceFlush = false) { if ($forceFlush === false) { $cachedCMSDataKeys = array(self::MENUS_KEY, self::MENUS_PATHS_KEY); $existingCachedCMSDataKeys = $this->cache->cacheAdapter->hasItems($cachedCMSDataKeys); } if ($forceFlush === true || $forceFlush === false && count($existingCachedCMSDataKeys) !== count($cachedCMSDataKeys)) { $menuItems = $this->menuItem->getMenuItems(); $menuItemsPaths = $this->query->setEntity('CMS\\Entity\\MenuItem')->entityRepository->getMenuItemsSorted(array(), true, true, true, "p.path as path", false); $menuItemsPathsFlat = array(); array_walk_recursive($menuItemsPaths, function ($value) use(&$menuItemsPathsFlat) { $menuItemsPathsFlat[] = $value; }); $items = array(self::MENUS_KEY => serialize($menuItems), self::MENUS_PATHS_KEY => serialize($menuItemsPathsFlat)); $this->cache->setItems($items); } else { $items = $this->getCachedCMSData(); $items = array(self::MENUS_KEY => serialize($items[self::MENUS_KEY]), self::MENUS_PATHS_KEY => serialize($items[self::MENUS_PATHS_KEY])); } return $items; }