Note that there are some explanatory texts on larger screens.

plurals
  1. POYii: Data Caching on other actions
    primarykey
    data
    text
    <p>I have an app which links twitter to it with the API, in this action I have a creation of a request key which is done here:</p> <pre><code> public function createRequestKey() { $this-&gt;setScenario(self::SCENARIO_DEFAULT); if (!$this-&gt;validate()) return false; $cache = \Yii::app()-&gt;cache; $key = __CLASS__ . '_' . $this-&gt;user-&gt;id . '_' . time() . '_' . rand(0, 100); $key = sha1($key); $data = array( 'userId' =&gt; $this-&gt;user-&gt;id, ); $cache-&gt;set($key, $data, 60 * 30); $this-&gt;requestKey = $key; return true; } </code></pre> <p>The action that calls this method is this:</p> <pre><code> public function actionTwitterLinkUrl() { if (!$this-&gt;checkOAuthRequest()) return; $request = \Yii::app()-&gt;getRequest(); $response = \Yii::app()-&gt;response-&gt;setContentTypeToJSON(); $user = $this-&gt;getUserFromHeader(); $this-&gt;matchUserToLastValidatedToken($user); $linker = new \Sakanade\Operations\APITwitterLinker($user); if ($linker-&gt;createRequestKey()) { $params = $this-&gt;createQueryStringParams($linker-&gt;requestKey); $response-&gt;set('type',UserProfile::profileTypeToString(UserProfile::PROFILETYPE_TWITTER)) -&gt;set('url', $request-&gt;getBaseUrl(true) . '/users/' . urlencode($user-&gt;id) . '/profiles/twitter/link?' . http_build_query($params)); } else { $response-&gt;setStatusCode(\Harusame\Components\HttpResponse::STATUS_BAD_REQUEST) -&gt;addMessage(\Sakanade\Models\Model::flattenErrorMessages($linker)); } $response-&gt;render(); } </code></pre> <p>But upon calling the next action, if I access the cache using $cache->get($key) it returns to false, even though it set the cache's storage time of about 1800 seconds.</p> <pre><code>public function actionTwitterRunLink() { $request = \Yii::app()-&gt;request; $requestKey = $request-&gt;getQuery('key'); if (!$this-&gt;checkOAuthRequest()) return; $user = $this-&gt;getUserFromHeader(); $this-&gt;matchUserToLastValidatedToken($user); $authUrl = $this-&gt;getAuthorizationUrl($user); $response = \Yii::app()-&gt;response-&gt;setContentTypeToJSON(); $cache = \Yii::app()-&gt;cache; $response-&gt;set('key', $cache-&gt;get($requestKey)) -&gt;set('key2', $requestKey); $response-&gt;render(); } </code></pre> <p>Upon displaying the rendered key from the cache it returns to false but if I try to get it from the previous action there is a returned value. Why is the cache cleared upon calling another action? Any help will be greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload