Thursday, July 16, 2009

Session Cache is not configured - Phusion Passenger

Got this error in the Apache error log while trying to setup Ruby on Rails app with Phusion Passenger on Mac OS X:

[Wed Jul 15 14:26:07 2009] [notice] caught SIGTERM, shutting down
[Wed Jul 15 14:26:07 2009] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]


Apache errors seem obtusely opaque.
Found the fix in this blog entry:
http://benr75.com/2008/04/12/setup-mod_rails-phusion-mac-os-x-leopard
The RailsEnv entry needs to be set correctly in the Apache httpd.conf VirtualHost element, like so:


<VirtualHost *>
ServerName app.test
DocumentRoot /Users/benr/Rails/app/public
RailsEnv development
</VirtualHost>


ServerName can be 'localhost' if you are running locally for development/testing.

Ruby Proc vs Lambda Comparision

Here's a more comprehensible explanation than what is in the Pickaxe book:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls#Understanding_blocks.2C_Procs_and_methods

In short, the difference between lambda and Proc is in whether the number of parameters is checked and the behavior of "return"
The resulting Proc object created by lambda checks the number of arguments and throws an ArgumentError. A Proc object created by Proc.new does not check the number of arguments.

The example from the link is:

lamb = lambda {|x, y| puts x + y}
pnew = Proc.new {|x, y| puts x + y}

# works fine, printing 6
pnew.call(2, 4, 11)

# throws an ArgumentError
lamb.call(2, 4, 11)


Second, a return from Proc.new returns from it's enclosing method,
while a return from a lambda Proc acts more "conventionally", returning to it's caller.
Here's an interesting quote "Blocks, as I see them, are unborn Procs. Blocks are the larval, Procs are the insects."

And an explanation of closure, a closely related concept:
http://en.wikipedia.org/wiki/Closure_(computer_science)
It has a ruby example of the difference of "return" behavior between lambda and Proc.