1 | <?php |
||
22 | class FileCache implements CacheInterface |
||
23 | { |
||
24 | private $path; |
||
25 | |||
26 | /** |
||
27 | * Initializes file cache. |
||
28 | * |
||
29 | * @param string $path Path to the folder where to store caches. |
||
30 | */ |
||
31 | 5 | public function __construct($path) |
|
39 | |||
40 | /** |
||
41 | * Checks that cache for feature exists and is fresh. |
||
42 | * |
||
43 | * @param string $path Feature path |
||
44 | * @param integer $timestamp The last time feature was updated |
||
45 | * |
||
46 | * @return Boolean |
||
47 | */ |
||
48 | 3 | public function isFresh($path, $timestamp) |
|
49 | { |
||
50 | 3 | $cachePath = $this->getCachePathFor($path); |
|
51 | |||
52 | 3 | if (!file_exists($cachePath)) { |
|
53 | 1 | return false; |
|
54 | } |
||
55 | |||
56 | 2 | return filemtime($cachePath) > $timestamp; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Reads feature cache from path. |
||
61 | * |
||
62 | * @param string $path Feature path |
||
63 | * |
||
64 | * @return FeatureNode |
||
65 | * |
||
66 | * @throws CacheException |
||
67 | */ |
||
68 | 2 | public function read($path) |
|
79 | |||
80 | /** |
||
81 | * Caches feature node. |
||
82 | * |
||
83 | * @param string $path Feature path |
||
84 | * @param FeatureNode $feature Feature instance |
||
85 | */ |
||
86 | 3 | public function write($path, FeatureNode $feature) |
|
90 | |||
91 | /** |
||
92 | * Returns feature cache file path from features path. |
||
93 | * |
||
94 | * @param string $path Feature path |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 5 | protected function getCachePathFor($path) |
|
102 | } |
||
103 |