fixed bugs in Cache, added tests