Imagine a web server for a simplified search engine.This system has WOmachines to respondtosearchqueries,whichmaythencalloutusingprocessSearch (string query) to another cluster of machines to actually get the result. The machine which responds to a given query is chosen at random, soyou can not guarantee that the same machine will always respond to the same request. Themethod process - Search is very expensive. Design a caching mechanism to cache the results of the most recent queries. Besure to explain how you would update the cache when data changes.
- LRU cache
- Expand to Many Machines. If each machine has its own cache, there is one disadvantage. If we have same popular queries to different machine, they all have to do query. If each machine has a copy of the cache, then updating the cache is a big task. So each machine could stores segment of the cache.
- Updating the cache. (instantly or periodically)