Fixed cache when output.write is true and also improved platform independence of caching