Guava Library Learning: Learning Guava Cache (vi) cachestats

Source: Internet
Author: User

Original address: Guava Library Learning: Learning Guava Cache (vi) cachestats

Previous article,Guava Library Learning: Learning Guava Cache (v) cacheloader , we learned Cacheloader abstract class, mainly from the method, To receive a function or supplier and return a Cacheloader instance, we have learned how to create a powerful caching mechanism, and then we want to collect some statistics after the cache is executed or used. Now start this article, Guava Cache cachestats learning.

The guava cache provides a very simple way to collect statistics on cache execution, and it is important to note that the tracking cache operation will result in a performance penalty, and to collect cached information, we only need to declare when we use cachebuilder that we want to collect statistics:

loadingcache<string,tradeaccount> Tradeaccountcache = Cachebuilder.newbuilder (). RecordStats ()

The above code, we construct a Loadingcache instance through the builder pattern, want to enable statistics of the cache information, the only thing we need to do is to build inside the builder.recordstats ()register, and want to get statistical information, we only need to call the stats () method through the cache or Loadingcache, we will return a cachestats instance, through the Cachestats instance can obtain the required statistics, see the following example:

Cachestats cachestats = Cache.stats ();

Here is an overview of a list of some of the information we can get through Cachestats:

    1. The average time spent loading cached entry values;

    2. The hit rate of the requested cache entry;

    3. The misses of the requested cache entry;

    4. The number of cache bars removed;

There is a lot of information involved in cache performance, the above list is just some of the information we get through cachestats, finally, we open the source of cachestats, to collate the public methods provided, as follows:

RequestCount (): Returns the cache's Lookup method to find the number of caches, regardless of whether the lookup value is cached.

HitCount (): Returns the number of cache hits cached by the lookup method of the cache.

Hitrate (): Returns the hit rate of the cache request, divided by the number of requests.

Misscount (): Returns the number of misses for the cache request.

Missrate (): Returns the ratio of cache request misses, the number of misses divided by the number of requests.

Loadcount (): Returns the number of times the cache calls the Load method to load a new value.

Loadsuccesscount (): Returns the number of times the cache has succeeded in loading a new value.

Loadexceptioncount (): Returns the number of times the cache loaded a new value with an exception.

Loadexceptionrate (): Returns the rate at which the cache loaded the new value with an exception.

Totalloadtime (): Returns the total time spent by the cache to load new values.

Averageloadpenalty (): The average time that the cache loads new values, the number of loads divided by the total time loaded.

Evictioncount (): Returns the number of times the entry in the cache has been removed.

Minus (Cachestats Other): Returns a new Cachestats instance that represents the difference between the current cachestats and the incoming cachestats.

Plus (Cachestats other): Returns a new Cachestats instance representing the total between the current cachestats and the incoming cachestats.

Guava Library Learning: Learning Guava Cache (vi) cachestats

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.