Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does flash.discard do? What's the difference from flash.clear()?

I haven't found any documentation on flash.discard(). What does it do?

like image 716
ripper234 Avatar asked Jan 30 '12 16:01

ripper234


2 Answers

After looking at the code, this is what I understand:

  1. The Flash data is ultimately for storing data between requests.
  2. Since Play is stateless, that state is saved in a session cookie, which is send to the client and send back with the next request.
  3. The data Map is the data that comes from the client via the cookie.
  4. The out Map is the data that the Play app writes to the Flash instance.
  5. If the data changed, the data in the out Map is used to build the content of the cookie to send back to the client.

So from this, I would say, that flash.discard() is used to throw away everything that would go to the client, and flash.clear() is used to throw away everything that came from the client...

like image 86
dertoni Avatar answered Nov 14 '22 23:11

dertoni


That's a good question. While I don't know the answer either, the source code at github should help:

https://github.com/playframework/play/blob/master/framework/src/play/mvc/Scope.java

A quick glance shows the Scope keeps two hashmaps, one named data and other named out. They both store the same information. But the flash.clear() is acting upon data and flash.discard() is acting upon out... Funny...

Better call both, just in case =)

like image 24
Filipe Miguel Fonseca Avatar answered Nov 15 '22 01:11

Filipe Miguel Fonseca