Make script cache configurable and bounded

Fixes #2539