I'm struggling with this, I need to store data in the browser's cache. I'm using Symfony 2.6.1, I use the following code:
if($request->cookies->get('myCookie')){ /* do stuff */ }else{ $cookie = new Cookie('myCookie', $myData, 0, '/', null, false, false); $response->headers->setCookie($cookie); $response->setCache(array( 'etag' => 'abcdef', 'last_modified' => new \DateTime(), 'max_age' => 600, 's_maxage' => 600, // 'private' => false, 'public' => true, )); $response->send(); /* send a response */ } I need to 1st check if the cookie "myCookie" exists, if not it should create and store in the browser. My problem is that, when I simply refresh the page to cookie is there, but if I close the browser, when I open again the cookie is not there.
I think that is some configuration/ propriety in the in the array when I set the cookie $response->setCache(array( ... ))
In the official site, there is not many helpful info about this.
http://symfony.com/doc/current/book/http_cache.html#types-of-caches