@Test public void testGet() throws Exception { TestTicker ticker = new TestTicker(); try (OHCache<Integer, String> cache = OHCacheBuilder.<Integer, String>newBuilder() .keySerializer(TestUtils.intSerializer) .valueSerializer(TestUtils.stringSerializer) .ticker(ticker) .timeouts(true) .build()) { cache.put(1, "one", ticker.currentTimeMillis() - 1); assertNull(cache.get(1)); cache.put(2, "two", ticker.currentTimeMillis() + 5); assertEquals(cache.get(2), "two"); ticker.addMillis(10); assertNull(cache.get(2)); } }
Timeouts(Ticker ticker, int slots, long precision) { if (slots == 0) slots = 64; if (precision == 0) precision = 128; if (slots < 1) throw new IllegalArgumentException("timeouts-slots <= 0"); if (precision < 1) throw new IllegalArgumentException("precision <= 0"); this.ticker = ticker; this.slotCount = Ints.checkedCast(Util.roundUpToPowerOf2(Math.max(slots, 16), 1 << 30)); int slotShift = 64 - Util.bitNum(slotCount) - 1; this.slotBitmask = ((long) slotCount - 1) << slotShift; this.slots = new Slot[slotCount]; for (int i = 0; i < slotCount; i++) this.slots[i] = new Slot(); precision = Util.roundUpToPowerOf2(Math.max(precision, 1), 1 << 30); precisionShift = 64 - Util.bitNum(precision) - 1; }
Timeouts { Timeouts(Ticker ticker, int slots, long precision) { if (slots == 0) slots = 64; if (precision == 0) precision = 128; if (slots < 1) throw new IllegalArgumentException("timeouts-slots <= 0"); if (precision < 1) throw new IllegalArgumentException("precision <= 0"); this.ticker = ticker; this.slotCount = Ints.checkedCast(Util.roundUpToPowerOf2(Math.max(slots, 16), 1 << 30)); int slotShift = 64 - Util.bitNum(slotCount) - 1; this.slotBitmask = ((long) slotCount - 1) << slotShift; this.slots = new Slot[slotCount]; for (int i = 0; i < slotCount; i++) this.slots[i] = new Slot(); precision = Util.roundUpToPowerOf2(Math.max(precision, 1), 1 << 30); precisionShift = 64 - Util.bitNum(precision) - 1; } }
Timeouts { Timeouts(Ticker ticker, int slots, long precision) { if (slots == 0) slots = 64; if (precision == 0) precision = 128; if (slots < 1) throw new IllegalArgumentException("timeouts-slots <= 0"); if (precision < 1) throw new IllegalArgumentException("precision <= 0"); this.ticker = ticker; this.slotCount = Ints.checkedCast(Util.roundUpToPowerOf2(Math.max(slots, 16), 1 << 30)); int slotShift = 64 - Util.bitNum(slotCount) - 1; this.slotBitmask = ((long) slotCount - 1) << slotShift; this.slots = new Slot[slotCount]; for (int i = 0; i < slotCount; i++) this.slots[i] = new Slot(); precision = Util.roundUpToPowerOf2(Math.max(precision, 1), 1 << 30); precisionShift = 64 - Util.bitNum(precision) - 1; } Timeouts(Ticker ticker, int slots, long precision); }
Timeouts { Timeouts(Ticker ticker, int slots, long precision) { if (slots == 0) slots = 64; if (precision == 0) precision = 128; if (slots < 1) throw new IllegalArgumentException("timeouts-slots <= 0"); if (precision < 1) throw new IllegalArgumentException("precision <= 0"); this.ticker = ticker; this.slotCount = Ints.checkedCast(Util.roundUpToPowerOf2(Math.max(slots, 16), 1 << 30)); int slotShift = 64 - Util.bitNum(slotCount) - 1; this.slotBitmask = ((long) slotCount - 1) << slotShift; this.slots = new Slot[slotCount]; for (int i = 0; i < slotCount; i++) this.slots[i] = new Slot(); precision = Util.roundUpToPowerOf2(Math.max(precision, 1), 1 << 30); precisionShift = 64 - Util.bitNum(precision) - 1; } Timeouts(Ticker ticker, int slots, long precision);  }
Timeouts { Timeouts(Ticker ticker, int slots, long precision) { if (slots == 0) slots = 64; if (precision == 0) precision = 128; if (slots < 1) throw new IllegalArgumentException("timeouts-slots <= 0"); if (precision < 1) throw new IllegalArgumentException("precision <= 0"); this.ticker = ticker; this.slotCount = Ints.checkedCast(Util.roundUpToPowerOf2(Math.max(slots, 16), 1 << 30)); int slotShift = 64 - Util.bitNum(slotCount) - 1; this.slotBitmask = ((long) slotCount - 1) << slotShift; this.slots = new Slot[slotCount]; for (int i = 0; i < slotCount; i++) this.slots[i] = new Slot(); precision = Util.roundUpToPowerOf2(Math.max(precision, 1), 1 << 30); precisionShift = 64 - Util.bitNum(precision) - 1; } Timeouts(Ticker ticker, int slots, long precision);   }