]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - feed/CachedPage.php
3 namespace Shaarli\Feed
;
5 * Simple cache system, mainly for the RSS/ATOM feeds
9 // Directory containing page caches
12 // Should this URL be cached (boolean)?
13 private $shouldBeCached;
15 // Name of the cache file for this URL
19 * Creates a new CachedPage
21 * @param string $cacheDir page cache directory
22 * @param string $url page URL
23 * @param bool $shouldBeCached whether this page needs to be cached
25 public function __construct($cacheDir, $url, $shouldBeCached)
27 // TODO: check write access to the cache directory
28 $this->cacheDir
= $cacheDir;
29 $this->filename
= $this->cacheDir
. '/' . sha1($url) . '.cache';
30 $this->shouldBeCached
= $shouldBeCached;
34 * Returns the cached version of a page, if it exists and should be cached
36 * @return string a cached version of the page if it exists, null otherwise
38 public function cachedVersion()
40 if (!$this->shouldBeCached
) {
43 if (is_file($this->filename
)) {
44 return file_get_contents($this->filename
);
50 * Puts a page in the cache
52 * @param string $pageContent XML content to cache
54 public function cache($pageContent)
56 if (!$this->shouldBeCached
) {
59 file_put_contents($this->filename
, $pageContent);