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 set($data) { $fileName = $this->getFilename(); $this->prepare(); $key = $this->getCacheKey(); self::$cache[$key] = $data; file_put_contents($fileName, PhpExporter::export($data)); @chmod($fileName, 0666); $this->nsCache->set(); return $data; }
/** * Add annotations namespace. * Every added namespace will be included in annotation name resolving for current instance. * * @param string $ns * @renturn Addendum */ public function addNamespace($ns) { NameNormalizer::normalize($ns, false); if (!in_array($ns, $this->namespaces)) { $before = count($this->namespaces); $this->namespaces[] = $ns; $this->namespaces = array_unique($this->namespaces); $after = count($this->namespaces); if ($after !== $before) { $this->nameKeys = array_flip($this->namespaces); Cache\NsCache::$addeNs = true; } $this->di->store($this, [], true); // Reconfigure flyweight instances if present if (!empty(self::$addendums[$this->instanceId])) { self::$addendums[$this->instanceId]->di->configure(self::$addendums[$this->instanceId]); } } return $this; }