/** * Turns a key array into a key string. This includes running the indexing functions used to manage the Redis * hierarchical storage. * * When requested the actual path, rather than a normalized value, is returned. * * @param array $key * @param bool $path * @return string */ protected function makeKeyString($key, $path = false) { $key = \Stash\Utilities::normalizeKeys($key); $keyString = 'cache:::'; $pathKey = ':pathdb::'; foreach ($key as $name) { //a. cache:::name //b. cache:::name0:::sub $keyString .= $name; //a. :pathdb::cache:::name //b. :pathdb::cache:::name0:::sub $pathKey = ':pathdb::' . $keyString; $pathKey = md5($pathKey); if (isset($this->keyCache[$pathKey])) { $index = $this->keyCache[$pathKey]; } else { $index = $this->redis->get($pathKey); $this->keyCache[$pathKey] = $index; } //a. cache:::name0::: //b. cache:::name0:::sub1::: $keyString .= '_' . $index . ':::'; } return $path ? $pathKey : md5($keyString); }
protected function createPool() { $cache_driver = tpenv('TP_CACHE_DRIVER', 'file'); switch ($cache_driver) { case 'redis': $driver = new Stash\Driver\Redis(); $server = Config::get('database.redis.default.host'); $port = Config::get('database.redis.default.port'); $database = Config::get('database.redis.default.database'); TPLog::debug('Server Config: ', ['server' => $server, 'port' => $port]); $driver->setOptions(['servers' => [[$server, $port]], 'database' => $database]); break; default: $driver = new Stash\Driver\FileSystem(); $driver->setOptions(['path' => $this->storagePath() . '/framework/cache/stash']); } $this->pool = new Stash\Pool($driver); }
protected function tearDown() { $this->redis->purge(); }