public function testIfWillProperlyCacheNamespacesForDifferentMetaContainers() { $path = (new ConfigDetector())->getRuntimePath(); if (!is_dir($path)) { mkdir($path); } // Simulate different meta container classes by creating different paths $path1 = sprintf('%s/path1', $path); $path2 = sprintf('%s/path2', $path); $path3 = sprintf('%s/path3', $path); if (!is_dir($path1)) { mkdir($path1); } if (!is_dir($path2)) { mkdir($path2); } if (!is_dir($path3)) { mkdir($path3); } $ns1 = new NsCache($path1, Addendum::fly(), new CacheOptionsOne()); $ns1->set(); codecept_debug($ns1->get()); $this->assertTrue($ns1->valid()); $ns2 = new NsCache($path2, Addendum::fly(), new CacheOptionsTwo()); $ns2->set(); codecept_debug($ns2->get()); $this->assertTrue($ns1->valid()); $this->assertTrue($ns2->valid()); $ns3 = new NsCache($path3, Addendum::fly(), new CacheOptionsOne()); $ns3->set(); codecept_debug($ns3->get()); $this->assertTrue($ns1->valid()); $this->assertTrue($ns2->valid()); $this->assertTrue($ns3->valid()); }
public function get() { $this->prepare(); $fileName = $this->getFilename(); if (NsCache::$addeNs && !$this->nsCache->valid()) { $this->clearCurrentPath(); return false; } $key = $this->getCacheKey(); if (isset(self::$cache[$key])) { return self::$cache[$key]; } $data = SoftIncluder::includeFile($fileName); // Only false means not existing cache. // NOTE: Cache might have valid `empty` value, ie. empty array. if (false === $data) { return false; } // Purge file cache if checkMTime is enabled and file obsolete if ($this->addendum->checkMTime && file_exists($fileName)) { $cacheTime = filemtime($fileName); // Partial component name, split by @ and take first argument if (is_string($this->component) && strstr($this->component, '@')) { $parts = explode('@', $this->component); $componentClass = array_shift($parts); } else { $componentClass = $this->component; } $componentTime = filemtime((new ReflectionClass($componentClass))->getFileName()); if ($componentTime > $cacheTime) { $this->remove(); return false; } } self::$cache[$key] = $data; return $data; }