Skip to content

Caching

omarathon edited this page Aug 11, 2019 · 4 revisions

Overview

MemorisingFilters (MatchFilters and SummonerFilters are both MemorisingFilters), the SummonerHistory and MemorisingEstimators all utilise caches, specifically Guava Caches.

Below explains the caching implemented in each of the above classes:

  • MemorisingFilters: we cache the boolean result from applying the filter on each input object.
  • SummonerHistory: we use a cache to store the visited Summoners, with their associated MatchHistory which was calculated in the crawl method of the Crawler.
  • MemorisingEstimators: we cache the result from applying the estimator on each input object.

Usage

The caching is automatically implemented into each of the classes. However, each class offers additional support to configure its inner cache. One may construct each of the above classes with an additional parameter: which is a CacheBuilder. The inner cache for each of the classes is created based upon the input CacheBuilder, and when it's not specified, a default one is used.

One may construct their own CacheBuilder by referring to Guava's CacheBuilder.

Example

For example, constructing a CacheBuilder which causes all entries to expire 3 hours after being written, with a maximum size of 1000 entries:

CacheBuilder.newBuilder()
   .expireAfterWrite(3, TimeUnit.HOURS)
   .maximumSize(1000);

Defaults

As said above, there are default implementations of caches for the three main classes which use them. Below lists the CacheBuilder properties for the default implementations in each of the three classes:

Class expireAfterWrite maximumSize
MemorisingFilter 3 hours 100,000
SummonerHistory 1 day 100,000
MemorisingEstimator 3 hours 100,000
Clone this wiki locally