MCPcopy Create free account
hub / github.com/ddf-project/DDF / DDFCache

Method DDFCache

core/src/main/java/io/ddf/DDFCache.java:38–68  ·  view source on GitHub ↗
(DDFManager manager)

Source from the content-addressed store, hash-verified

36 private DDFManager mDDFManager;
37
38 public DDFCache(DDFManager manager) {
39
40 mDDFManager = manager;
41
42 /**
43 * Maximum number of DDFs without name allowed in cache, DDFs will be evicted by an approximate LRU algorithm
44 */
45 Long maxNumberOfDDFs = Long.valueOf(Config.getGlobalValue(Config.ConfigConstant.MAX_NUMBER_OF_DDFS_IN_CACHE));
46
47 /**
48 * Maximum number of DDFs with name allowed in cache, DDFs with name will be evicted by an approximate LRU algorithm
49 */
50 Long maxNumberOfDDFsWName = Long
51 .valueOf(Config.getGlobalValue(Config.ConfigConstant.MAX_NUMBER_OF_DDFS_WITH_NAME_IN_CACHE));
52
53 /**
54 * The number of seconds that the DDF will live in cache since it last used(meaning inserted or accessed)
55 */
56 Long timeToIdle = Long.valueOf(Config.getGlobalValue(Config.ConfigConstant.DDF_TIME_TO_IDLE_SECONDS));
57
58 mLog.info(String.format("Maximum number of ddfs in cache %s", maxNumberOfDDFs));
59 mLog.info(String.format("DDF's time to idle = %s seconds", timeToIdle));
60
61 mDDFCache = CacheBuilder.newBuilder().
62 maximumSize(maxNumberOfDDFs).expireAfterAccess(timeToIdle, TimeUnit.SECONDS).
63 recordStats().removalListener(new DDFRemovalListener()).build();
64
65 // Don't do time based eviction for DDF with name
66 mDDFwithNameCache = CacheBuilder.newBuilder().
67 maximumSize(maxNumberOfDDFsWName).recordStats().removalListener(new DDFRemovalListener()).build();
68 }
69
70 private boolean containsDDF(UUID uuid) {
71 return (mDDFCache.asMap().containsKey(uuid) || mDDFwithNameCache.asMap().containsKey(uuid));

Callers

nothing calls this directly

Calls 2

getGlobalValueMethod · 0.95
buildMethod · 0.80

Tested by

no test coverage detected