public synchronized T get() {
        long now = clock.millis();
        if (cachedInstance == null || (now - lastRefreshTimestamp) >= cacheDurationMillis) {
            cachedInstance = supplier.get();
            lastRefreshTimestamp = now;
        }

        return cachedInstance;
    }
@Test
    public void testCache() {

        AtomicLong currentTime = new AtomicLong(0);

        Clock clock = mock(Clock.class);
        when(clock.millis()).then(invocation -> currentTime.longValue());

        AtomicInteger currentValue = new AtomicInteger(0);

        Supplier<Integer> cache = new ObjectCache<>(() -> currentValue.getAndIncrement(),
                10, TimeUnit.MILLISECONDS, clock);

        cache.get();
        assertEquals(cache.get().intValue(), 0);
        assertEquals(cache.get().intValue(), 0);

        currentTime.set(1);
        // Still the value has not expired
        assertEquals(cache.get().intValue(), 0);

        currentTime.set(10);
        assertEquals(cache.get().intValue(), 1);


        currentTime.set(15);
        assertEquals(cache.get().intValue(), 1);

        currentTime.set(22);
        assertEquals(cache.get().intValue(), 2);
    }