moved cache handling to central function as a preparation for fs cache
Added support for a generic var cache