Added CacheUpdate events. Some refactoring. Added tests.