Clamp frame index to valid range in Cache. Partially fixes #38.