added simple caching of query kernel matrix