I have in my config web
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
]
and a form with email. In my controller, I want to cache the count of how many time the same email posted.
if($model->load(Yii::$app->request->post()) && $model->validate()){
$counter = \Yii::$app->cache->get('antiflood-'.$model->email);
if($counter === false){
\Yii::$app->cache->set('antiflood-'..$model->email,1,86400);
} else {
\Yii::$app->cache->set('antiflood-'.$model->email,$counter+1,86400);
}
var_dump(Yii::$app->cache->get(''antiflood-'.$model->email));
exit;
}
After I submit form, count is increased.If I refresh my page, I have confirmation from chrome and I see
If I click continue it's working fine. But if I go back to form and enter same email, I see again 1 output i.e again go to if condition but need to go to else because I already set id with same email. What is wrong here? Can anyone suggest me. Thank You.