0

Laravel 8 has config file config\session.php

this file has 2 parameters to store

'driver' => env('SESSION_DRIVER', 'file'),

and

'store' => env('SESSION_STORE', null)

Both can be "apc", "dynamodb", "memcached", "redis"

The only difference I see is that 'driver' can also be "file", "cookie", "database", "array"

Please tell me what is the difference and why do we have 2 parameters there?

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191

1 Answers1

2

Essentially, it allows you to configure a separate CACHE_STORE from your SESSION_STORE.

Imagine you have APIv1 where you are caching queries using encrypted cache keys in Redis along with caching your User Sessions also in Redis.

Let's say you want to rollout APIv2 and want to clear all of your cached queries but not Log all of your users out.

If you're CACHE_STORE and SESSION_STORE are the same instance of a Redis Store you can not run php artisan cache:clearwithout clearing both stores. And hunting down all of the encrypted cache keys you want to clear would be very difficult and time consuming.

However, if you setup your User Sessions on a separate Redis Store you can run it with confidence.

This is an example of why someone would use CACHE_STORE or SESSION_STORE, each of which can be pointed to separate Redis Database/Instances that you have configured in config/database.php.

Azeame
  • 2,322
  • 2
  • 14
  • 30
  • Thank you, but I think you are answering a wrong question. Your answer is good for `CACHE_STORE` vs `SESSION_STORE`, but the question is about `“SESSION_STORE”` vs `''SESSION_DRIVER"` – Yevgeniy Afanasyev Jul 27 '21 at 05:15
  • You're not getting it. If you created a second Redis instance in your config, it wouldn't be named Redis anymore, but probably Redis-2, then you would still be using the same Redis driver, but the store would now be redis-2. – Azeame Jul 27 '21 at 13:39
  • Thank you, Azeame. You comment makes sense, but your answer is still irrelevant. Maybe you could make a second asnwer about redis-2 with more details, because I'm still confused. I understand that even if I had a a redis-2 instance, I would still be using it in the `config/database.php` to give a name for a connection, and then I'm sill going to use this connection in the `config\session.php` to set `driver`. Why do I need a `store`? – Yevgeniy Afanasyev Jul 27 '21 at 22:44