Fixed bug with template caching.

Now cache validates if template has changed or not.  Also fixed bug of
applying prefixes to calculated field names.