Search code examples
javaweb-servicescachingguavagoogle-guava-cache

How does Guava caching stand in terms of performance?


I want to use Guava caching mechanism to cache request-response pair of webservice calls to improve performance of website. But, before going ahead with solution want to know how does Guava caching stand in terms of performance?

Thanks, Ashish.


Solution

  • Any in-memory cache is always significantly faster (magnitudes) than a round-trip to a database, file, another service, ... (talking to other computers or the file system is really, REALLY expensive compared to just a fetch from memory) Google Guava's cache is basically a Map that automatically triggers some fetching code if the key you're searching for isn't present (along with some automated eviction if you so choose). The Guava wiki page on cache explains it all. If for some reason this cache becomes a bottleneck (based on profiling, not "let me wet my finger and feel which way the wind is blowing"), it's much more likely the hardware you're running on isn't sufficient for the number of requests you're trying to handle, because a Map data structure is pretty much as low level as it gets in Java.