/** * Is the $url in our cache and still valid? * * @param string $url URL to check for cache * @return bool */ public function isPageCached($url) { $cache_length = trim($this->fetchConfig('cache_length', false)); // if no cache-length is set, this feature is off if (!(bool) $cache_length) { return false; } if ($this->fetchConfig('ignore_query_strings', false, null, true)) { $url = $this->removeQueryString($url); } // create the hash now so we don't have to do it many times below $url_hash = Helper::makeHash($url); // we're no longer allowing `on cache update` here, as its a flawed concept: // it only appeared to work because new pages were being hit, however, once // every page is hit and then HTML-cached, the cache will no longer update // because procedurally, that happens *after* we look for and load a version // that has been cached if ($cache_length == 'on cache update' || $cache_length == 'on last modified') { // ignore the cached version if the last modified time of this URL's // content file is newer than when the cached version was made // check that the URL being requested is a content file $bare_url = strpos($url, '?') !== false ? substr($url, 0, strpos($url, '?')) : $url; $data = ContentService::getContent($bare_url); $age = time() - File::getLastModified($data['_file']); // return if the cache file exists and if it's new enough return $this->cache->exists($url_hash) && $this->cache->getAge($url_hash) <= $age; } else { // purge any cache files older than the cache length $this->cache->purgeFromBefore('-' . $cache_length); // return if the file still exists return $this->cache->exists($url_hash); } }
/** * Gets cached content for pages for a certain taxonomy type and value * * @param string $taxonomy Taxonomy to use * @param string $values Values to match (single or array) * @param mixed $folders Optionally, folders to filter down by * @return ContentSet */ public static function getContentByTaxonomyValue($taxonomy, $values, $folders = null) { self::loadCache(); $case_sensitive = Config::getTaxonomyCaseSensitive(); if ($folders) { $folders = Parse::pipeList($folders); } // if an array was sent if (is_array($values)) { $files = array(); if (!$case_sensitive) { $values = array_map('strtolower', $values); } // loop through each of the values looking for files foreach ($values as $value) { if (!isset(self::$cache["taxonomies"][$taxonomy][$value])) { continue; } // add these file names to the big file list $files = array_merge($files, self::$cache["taxonomies"][$taxonomy][$value]['files']); } // get unique list of files $files = array_unique($files); // if a single value was sent } else { if (!$case_sensitive) { $values = strtolower($values); } if (!isset(self::$cache["taxonomies"][$taxonomy][$values])) { $files = array(); } else { $files = self::$cache["taxonomies"][$taxonomy][$values]['files']; } } // if no files, abort if (!count($files)) { return new ContentSet(array()); } // still here? grab data from cache $data = array(); foreach ($files as $file) { $data[] = ContentService::getContent($file); } // build a new ContentSet with the data we have $content_set = new ContentSet($data); // if there are folders to filter on, filter if ($folders) { $content_set->filter(array("folders" => $folders)); } return $content_set; }