Script cache

Added Caching to scripts.
isCacheMiss and getCacheIndex seem redundent, isCacheMiss could be implemented as getCacheIndex(name) == -1 instead of repeating the code