1 7 8 9 package com.hp.hpl.jena.db.impl; 12 13 import java.util.*; 16 17 import com.hp.hpl.jena.util.CollectionFactory; 18 19 20 29 30 public class SimpleCache implements ICache { 31 32 33 protected Map cache = CollectionFactory.createHashedMap(); 34 35 36 protected int threshold; 37 38 39 protected int count = 0; 40 41 47 public SimpleCache(int threshold) { 48 this.threshold = threshold; 49 } 50 51 56 public void put(IDBID id, Object val) { 57 if (threshold == 0) return; 58 if (threshold > 0 && count >= threshold) { 59 cache = CollectionFactory.createHashedMap(); 60 count = 0; 61 } 62 count++; 63 cache.put(id, val); 64 } 65 66 71 public Object get(IDBID id) { 72 return cache.get(id); 73 } 74 75 83 public void setLimit(int threshold) { 84 this.threshold = threshold; 85 if (threshold >= 0 && count > threshold) { 86 cache = CollectionFactory.createHashedMap(); 87 count = 0; 88 } 89 } 90 91 94 public int getLimit() { 95 return threshold; 96 } 97 } 98 124 125 126 | Popular Tags |