Guva local cache

foreword

Recently, a local cache needs to be used in a project. After online research, I found that the cache module provided by Google's Guva is very good. Simple and easy-to-use api; flexible and powerful functions, coupled with the golden sign of Google, made me choose it without hesitation. This blog only records the bits and pieces of my use in the process.

what is local cache

In our application, most of the computations are expensive and reusable, and the results of computations do not change frequently. At this time, we can cache these expensive calculation results in memory, and fetch them directly when we use them next time without recalculating them. This can save a lot of cpu and memory resources and improve the throughput of the system.

Since the local cache caches the calculation results in memory, we often need to set a maximum capacity to prevent memory overflow; when the number of caches approaches or exceeds the maximum capacity we set, we also need to formulate a cache elimination strategy to Weed out those results that we thought had the least value.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325171623&siteId=291194637