/** * Constructor. * * @param $limit The maximum amount of tags to include in the cloud. * @param $cacheKey Set this optional value to attempt to store the tag cloud array in the available cache for 24hrs (cache.provider.name). * * @since 1.0 */ public function __construct($limit, $cacheKey = '') { $config = ConfigProvider::getInstance(); self::$logger = new Logger('TagCloud'); if ($cacheKey != '' && $config->get('cache.provider.name') != '') { $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); $this->popTags = $cache->get($cacheKey); // cache look-up failed, so add it for the next time if (!$this->popTags) { self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] failed, regenerating popular tags...'); $this->popTags = Tag::getPopularTagsArray($limit); $cache->set($cacheKey, $this->popTags, 86400); } else { $this->popTags = array_slice($this->popTags, 0, $limit); self::$logger->debug('Cache lookup on the key [' . $cacheKey . '] succeeded'); } } else { $this->popTags = Tag::getPopularTagsArray($limit); } }