]>
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 // Should this URL be cached (boolean)?
11 private $shouldBeCached;
13 // Name of the cache file for this URL
17 * Creates a new CachedPage
19 * @param string $cacheDir page cache directory
20 * @param string $url page URL
21 * @param bool $shouldBeCached whether this page needs to be cached
23 public function __construct($cacheDir, $url, $shouldBeCached)
25 // TODO: check write access to the cache directory
26 $this->cacheDir
= $cacheDir;
27 $this->filename
= $this->cacheDir
.'/'.sha1($url).'.cache';
28 $this->shouldBeCached
= $shouldBeCached;
32 * Returns the cached version of a page, if it exists and should be cached
34 * @return string a cached version of the page if it exists, null otherwise
36 public function cachedVersion()
38 if (!$this->shouldBeCached
) {
41 if (is_file($this->filename
)) {
42 return file_get_contents($this->filename
);
48 * Puts a page in the cache
50 * @param string $pageContent XML content to cache
52 public function cache($pageContent)
54 if (!$this->shouldBeCached
) {
57 file_put_contents($this->filename
, $pageContent);