]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/CachedPage.php
3 * Simple cache system, mainly for the RSS/ATOM feeds
7 // Directory containing page caches
10 // Full URL of the page to cache -typically the value returned by pageUrl()
13 // Should this URL be cached (boolean)?
14 private $shouldBeCached;
16 // Name of the cache file for this URL
20 * Creates a new CachedPage
22 * @param string $cacheDir page cache directory
23 * @param string $url page URL
24 * @param bool $shouldBeCached whether this page needs to be cached
26 public function __construct($cacheDir, $url, $shouldBeCached)
28 // TODO: check write access to the cache directory
29 $this->cacheDir
= $cacheDir;
31 $this->filename
= $this->cacheDir
.'/'.sha1($url).'.cache';
32 $this->shouldBeCached
= $shouldBeCached;
36 * Returns the cached version of a page, if it exists and should be cached
38 * @return string a cached version of the page if it exists, null otherwise
40 public function cachedVersion()
42 if (!$this->shouldBeCached
) {
45 if (is_file($this->filename
)) {
46 return file_get_contents($this->filename
);
52 * Puts a page in the cache
54 * @param string $pageContent XML content to cache
56 public function cache($pageContent)
58 if (!$this->shouldBeCached
) {
61 file_put_contents($this->filename
, $pageContent);