PersistentObjectCacheWithMRUSort extends PersistentObjectCache<O> { public Collection<O> valuesByMostRecentlyUsed() { return mruSorter.values(); } PersistentObjectCacheWithMRUSort(
            String name,
            ShutdownHooks shutdownHooks,
            boolean recordStats,
            boolean startWithRefresh,
            final MruPromotionStrategy<O> mruPromotionStrategy);  PersistentObjectCacheWithMRUSort(
            String name,
            ShutdownHooks shutdownHooks,
            DataRefresher<O> refresher,
            Duration refreshInterval,
            boolean recordStats,
            boolean startWithRefresh,
            final MruPromotionStrategy<O> mruPromotionStrategy); @Override Future<Integer> addSort(
            String id, SortKeyFactory<O, T> factory); void touch(O object); Collection<O> valuesByMostRecentlyUsed(); Sorter<O> getMruSorter(); static final String MRU_SORT_ID; }
@Test public void testDupHandling() { PersistentObjectCacheWithMRUSort<Bam> cache = builder.withRefresher(new NoopRefresher<Bam>()) .withMruSort().build(); Bam first = new Bam(1, "first"); Bam firstDuplicate = new Bam(1, "second"); CurrentTime.freezeAt(1000); cache.put(first); CurrentTime.freezeAt(2000); cache.put(firstDuplicate); Assert.assertEquals(1, cache.valuesByMostRecentlyUsed().size()); }
@Test public void testPromoteAlways() { PersistentObjectCacheWithMRUSort<Bam> cache = builder.withRefresher(new NoopRefresher<Bam>()) .withMruSort().promoteWhenNewOrUpdated().build(); Bam first = new Bam(1, "first"); Bam second = new Bam(2, "second"); CurrentTime.freezeAt(1000); cache.put(first); CurrentTime.freezeAt(2000); cache.put(second); CurrentTime.freezeAt(3000); cache.put(first); Assert.assertEquals(first, cache.valuesByMostRecentlyUsed().iterator().next()); }
@Test public void testPromoteOnlyNew() { PersistentObjectCacheWithMRUSort<Bam> cache = builder.withRefresher(new NoopRefresher<Bam>()) .withMruSort().promoteWhenNewOnly().build(); Bam first = new Bam(1, "first"); Bam second = new Bam(2, "second"); CurrentTime.freezeAt(1000); cache.put(first); CurrentTime.freezeAt(2000); cache.put(second); CurrentTime.freezeAt(3000); cache.put(first); Assert.assertEquals(second, cache.valuesByMostRecentlyUsed().iterator().next()); }