lib/core: Improved cache mechanism in `ropes` for `substring` and `[]`