Generic cache implementation