diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
commit | d9f6275ebca035fec8331652c677981056793ccc (patch) | |
tree | 37a64baf4f0eba6b781040605965383d8aded2cc /application/CachedPage.php | |
parent | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff) | |
parent | d63ff87a009313141ae684ec447b902562ff6ee7 (diff) | |
download | Shaarli-stable.tar.gz Shaarli-stable.tar.zst Shaarli-stable.zip |
Merge branch 'v0.11' into stablestable
Diffstat (limited to 'application/CachedPage.php')
-rw-r--r-- | application/CachedPage.php | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/application/CachedPage.php b/application/CachedPage.php deleted file mode 100644 index e11cc52d..00000000 --- a/application/CachedPage.php +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Simple cache system, mainly for the RSS/ATOM feeds | ||
4 | */ | ||
5 | class CachedPage | ||
6 | { | ||
7 | // Directory containing page caches | ||
8 | private $cacheDir; | ||
9 | |||
10 | // Should this URL be cached (boolean)? | ||
11 | private $shouldBeCached; | ||
12 | |||
13 | // Name of the cache file for this URL | ||
14 | private $filename; | ||
15 | |||
16 | /** | ||
17 | * Creates a new CachedPage | ||
18 | * | ||
19 | * @param string $cacheDir page cache directory | ||
20 | * @param string $url page URL | ||
21 | * @param bool $shouldBeCached whether this page needs to be cached | ||
22 | */ | ||
23 | public function __construct($cacheDir, $url, $shouldBeCached) | ||
24 | { | ||
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; | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Returns the cached version of a page, if it exists and should be cached | ||
33 | * | ||
34 | * @return string a cached version of the page if it exists, null otherwise | ||
35 | */ | ||
36 | public function cachedVersion() | ||
37 | { | ||
38 | if (!$this->shouldBeCached) { | ||
39 | return null; | ||
40 | } | ||
41 | if (is_file($this->filename)) { | ||
42 | return file_get_contents($this->filename); | ||
43 | } | ||
44 | return null; | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Puts a page in the cache | ||
49 | * | ||
50 | * @param string $pageContent XML content to cache | ||
51 | */ | ||
52 | public function cache($pageContent) | ||
53 | { | ||
54 | if (!$this->shouldBeCached) { | ||
55 | return; | ||
56 | } | ||
57 | file_put_contents($this->filename, $pageContent); | ||
58 | } | ||
59 | } | ||