refactored app.cache handler for off-by-one error