Reputation: 1340
I have two methods that are called via ajax: The slow one that is called first (sleep is just used to illustrate a method that takes longer to return):
sleep(10);
return Session::get('bucket');
The second one that is called and finishes before the above method:
Session::push('bucket', 'Test');
return Session::get('bucket');
The second one returns the bucket with 'test' in it but when the slow one finishes it returns nothing because it thinks the array is empty even though the second method added something to it.
So is the session cached from when a controller method is first called? It seems like it but I'm not sure.
Cheers!
Upvotes: 0
Views: 85
Reputation: 19781
The sessions are started by the StartSession middleware. As it is a middleware, it is executed before the action is invoked, and completed afterwards.
What your second fast requests adds to the session will not be seen to the slower request since the slow request has already read the entire session content (which was empty at that time).
Here's a related fact; your slower request will also write the session content to disk at the end of the request. It will overwrite what your faster request has written to disk. This can easily bring problems when using concurrent requests (usually ajax requests) that modifies the session.
Relevant issues:
Upvotes: 2