]>
src.bluestatic.org Git - hoplite.git/blob - file_cache_backend.php
b4c9952714ebb741cc35f1657dd5064afec12c4b
3 // Copyright (c) 2013 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite\views
;
19 require_once HOPLITE_ROOT
. '/views/cache_backend.php';
22 An instance of a CacheBackend that writes cached representations to the file
23 system in temporary files.
25 class FileCacheBackend
implements CacheBackend
27 /*! @var string The cache path for templates. This should be a path, to which
28 the cached template name will be appended. This should not
29 end with a trailing slash.
31 protected $cache_path = '/tmp/phalanx_views';
33 public function cache_path() { return $this
->cache_path
; }
35 public function __construct($cache_path)
37 $this->cache_path
= $cache_path;
40 public function GetTemplateDataForName($name, $tpl_mtime)
42 $cache_path = $this->_CachePath($name);
44 // Make sure the cached file exists and hasn't gotten out-of-date.
45 if (!file_exists($cache_path) || filemtime($cache_path) < $tpl_mtime)
48 // Load the contents of the cache.
49 $data = @file_get_contents($cache_path);
56 public function StoreCompiledTemplate($name, $mtime, $data)
58 $cache_path = $this->_CachePath($name);
61 if (file_put_contents($cache_path, $data) === FALSE)
62 throw new TemplateLoaderException('Could not cache ' . $name . ' to ' . $cache_path);
65 public function GetMultipleTemplates(Array $fetch_templates)
70 /*! Returns the cache path for a given template name. */
71 protected function _CachePath($name)
73 return $this->cache_path
. $name . '.phpi';