<div dir="ltr"><div>Given that no-one has replied to this thread yet, could someone perhaps share an example of how they use Dancer2::Session::Memcached for sessions?<br><br></div><div>I was hoping to continue building my app in Dancer2, but it seems I may be better off reverting to Dancer at this stage, especially given many inconsistencies in the docs versus changes in Dancer2.<br>
</div><div><br></div>Thanks.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 8 April 2013 13:17, Dale Gallagher <span dir="ltr"><<a href="mailto:dale.gallagher@gmail.com" target="_blank">dale.gallagher@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi all<br><br></div>I converted my Dancer app to Dancer2 and have no issues when using Dancer2::Session::Simple. Sessions persist across routes.<br>
<br>However, on switching to Dancer2::Session::Memcached, after setting the session via the /login route, it's not accessible via another route. I know that the Memcached instance is functional, having tested it using a regular Perl script with Cache::Memcached.<br>
<br></div><div>Any ideas? I don't see any errors from Dancer.<br></div><div><br></div><div>Details:<br><br></div><div>Dancer2 (0.03)<br><br></div><div> cd /srv/web/app1/core/<br></div><div> setuidgid web1 ./bin/<a href="http://app.pl" target="_blank">app.pl</a><br>
<br></div><div>Tokyo Cabinet 1.4.48<br></div><div>Tokyo Tyrant 1.1.41<br><br></div><div> setuidgid web1 ttserver -host /srv/web/app1/sock/sessions.sock -port 0 /srv/web/app1/data/casket.tch<br></div><div><br></div><div>
pertinent part of config.yml<br>
<br>logger: "console"<br>log: "core"<br>warnings: 1<br>show_errors: 1<br><br>session: Memcached<br><br>engines:<br> session:<br> Memcached:<br> memcached_servers: /srv/web/app1/sock/sessions.sock<br>
<br></div><div>This works:<br><br></div><div>post '/login' => sub {<br></div><div> if (authen(params->{'user'}, params->{'pass'}) {<br></div><div> session 'user' => params->{'user'};<br>
</div><div> return 'user = ' . session('user');<br></div><div> }<br></div><div> else {<br></div><div> return redirect '/login';<br></div><div> }<br></div><div>}<br></div><div><br></div><div>
These 2 routes always end up back at /login:<br><br><div>post '/login' => sub {<br></div><div> if (authen(params->{'user'},params->{'pass'}) {<br></div><div> session 'user' => params->{'user'};<br>
</div><div> return redirect '/dashboard';<br></div><div> }<br></div><div> else {<br></div><div> return redirect '/login';<br></div><div> }<br></div><div>}<br></div><div><br></div></div><div>get '/dashboard' => sub {<br>
</div><div> if (not session('user')) {<br></div><div> return redirect '/login';<br></div><div> }<br></div><div> # do something<br></div><div>}<br></div><div><br></div><div>Even replacing the last route with the following, leaves an empty session (i.e. user is BLANK).<br>
<br><div>get '/dashboard' => sub {<br></div><div> return 'user is ' . session('user');<br></div><div>}<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>
<br></div>Dale<br></font></span></div><div><br></div><div><br></div></div>
</blockquote></div><br></div>