Fix bug in optimize
Handle too-many-open-files better in cached_open