Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii:其他操作上的数据缓存_Php_Caching_Yii_Twitter - Fatal编程技术网

Php Yii:其他操作上的数据缓存

Php Yii:其他操作上的数据缓存,php,caching,yii,twitter,Php,Caching,Yii,Twitter,我有一个应用程序通过API将twitter链接到它,在这个操作中,我创建了一个请求密钥,在这里完成: public function createRequestKey() { $this->setScenario(self::SCENARIO_DEFAULT); if (!$this->validate()) return false; $cache = \Yii::app()->cache; $key = __C

我有一个应用程序通过API将twitter链接到它,在这个操作中,我创建了一个请求密钥,在这里完成:

 public function createRequestKey()
 {
     $this->setScenario(self::SCENARIO_DEFAULT);
     if (!$this->validate())
         return false;

     $cache = \Yii::app()->cache;
     $key = __CLASS__ . '_' . $this->user->id . '_' . time() . '_' . rand(0, 100);
     $key = sha1($key);
     $data = array(
         'userId' => $this->user->id,      
     );
     $cache->set($key, $data, 60 * 30);
     $this->requestKey = $key;
     return true;
 }
调用此方法的操作如下:

 public function actionTwitterLinkUrl()
 {
    if (!$this->checkOAuthRequest())
        return;

    $request  = \Yii::app()->getRequest();
    $response = \Yii::app()->response->setContentTypeToJSON();

    $user = $this->getUserFromHeader();
    $this->matchUserToLastValidatedToken($user);

    $linker = new \Sakanade\Operations\APITwitterLinker($user);
    if ($linker->createRequestKey()) {
        $params = $this->createQueryStringParams($linker->requestKey);
        $response->set('type',UserProfile::profileTypeToString(UserProfile::PROFILETYPE_TWITTER))
                 ->set('url', $request->getBaseUrl(true) . '/users/' . urlencode($user->id)
                 . '/profiles/twitter/link?' . http_build_query($params));
    } else {
        $response->setStatusCode(\Harusame\Components\HttpResponse::STATUS_BAD_REQUEST)
                 ->addMessage(\Sakanade\Models\Model::flattenErrorMessages($linker));
    }

    $response->render();
 }
但是在调用下一个操作时,如果我使用$cache->get($key)访问缓存,它将返回false,即使它将缓存的存储时间设置为大约1800秒

public function actionTwitterRunLink()
{
    $request = \Yii::app()->request;
    $requestKey = $request->getQuery('key');
    if (!$this->checkOAuthRequest())
        return;

    $user = $this->getUserFromHeader();
    $this->matchUserToLastValidatedToken($user);

    $authUrl = $this->getAuthorizationUrl($user);
    $response = \Yii::app()->response->setContentTypeToJSON();
    $cache = \Yii::app()->cache;
    $response->set('key', $cache->get($requestKey))
             ->set('key2', $requestKey);
    $response->render();
}

从缓存中显示呈现的键时,它将返回false,但如果我尝试从上一个操作中获取它,则会返回一个值。为什么调用另一个操作时缓存被清除?任何帮助都将不胜感激

如果im未出错,如果未从“now”引用缓存时间 我认为应该是:

$cache->set($key, $data, time() + (60 * 30));

如果我没有弄错缓存时间如果不是从“现在”引用 我认为应该是:

$cache->set($key, $data, time() + (60 * 30));

少一点不相关的代码和缓存配置会有帮助…少一点不相关的代码和缓存配置会有帮助。。。