4 * This file is part of the Behat Gherkin.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Gherkin\Cache;
13 use Behat\Gherkin\Node\FeatureNode;
17 * Caches feature into a memory.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class MemoryCache implements CacheInterface
23 private $features = array();
24 private $timestamps = array();
27 * Checks that cache for feature exists and is fresh.
29 * @param string $path Feature path
30 * @param integer $timestamp The last time feature was updated
34 public function isFresh($path, $timestamp)
36 if (!isset($this->features[$path])) {
40 return $this->timestamps[$path] > $timestamp;
44 * Reads feature cache from path.
46 * @param string $path Feature path
50 public function read($path)
52 return $this->features[$path];
56 * Caches feature node.
58 * @param string $path Feature path
59 * @param FeatureNode $feature Feature instance
61 public function write($path, FeatureNode $feature)
63 $this->features[$path] = $feature;
64 $this->timestamps[$path] = time();