Add session, cache and some template work

This is almost ready for a first release (tests missing though).