3

I've read about the

\Drupal::service('user.private_tempstore')->get('mymodule_name');

and found similar to storing data in $_SESSION.

I am using user.private_tempstore in my module to store some data related to the user for a current session but when I logout and login again to the system found the value still persist in that variable. It is supposed to delete on logout.

To store data

  $userSession = \Drupal::service('user.private_tempstore')->get('user_profile');
  $userSession->set('user_profile', TRUE);

To get data

  $userSession = \Drupal::service('user.private_tempstore')->get('user_profile');
  $user_profile = $userSession->get('user_profile');

Is my understanding wrong?

1 Answer 1

2

Private tempstore data isn't deleted when you log out, it is usually deleted after a predefined, fixed amount of time.

If you want data that is deleted on logout, then either store in the session or store it somewhere with a random key that you put into a session (Useful when it is data that is no commonly needed on every request and/or larger than just a simple scalar value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.