Implement template PreCache-ing in the TemplateLoader.
[hoplite.git] / views / cache_backend.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2013 Blue Static
4 //
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.
8 //
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
12 // more details.
13 //
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/>.
16
17 namespace hoplite\views;
18
19 /*!
20 CacheBackend is used by the TemplateLoader to store and retrieve compiled
21 templates.
22 */
23 interface CacheBackend
24 {
25 /*!
26 Gets the compiled template data for the template of the given name.
27
28 If the template modification time is newer than what is stored in the cache,
29 this function should discard the item and return NULL.
30
31 @param string The name of the template.
32 @param int The UNIX timestamp the uncompiled template was last modified.
33
34 @return string|NULL The cached template data, or NULL if it is not cached.
35 */
36 public function GetTemplateDataForName($name, $modification_time);
37
38 /*!
39 Stores the compiled template data into the cache with the given name and
40 template modification time.
41
42 @param string The name of the template.
43 @param string The compiled template data.
44 @param int The UNIX timestamp the uncompiled template was last modified.
45 */
46 public function StoreCompiledTemplate($name, $modification_time, $data);
47
48 /*!
49 Gets a set of templates from the cache in bulk. If the backend doesn't
50 support bulk fetch operations, just loop over GetTemplateDataForName.
51
52 @param array Map of template names to modification times.
53
54 @return array Map of template names to data for templates that are present
55 and valid in the cache.
56 */
57 public function GetMultipleTemplates(Array $templates);
58 }