/** * Checks whether a given {@link ObjectId} is already cached on this {@code ObjectCache} */ public boolean contains(ObjectId id) { return sharedCache.get().contains(keyPrefix.create(id)); }
/** * Returns the cached object with the given id, if present, or {@code null} otherwise */ public @Nullable RevObject getIfPresent(ObjectId id) { return sharedCache.get().getIfPresent(keyPrefix.create(id)); } }
/** * Prunes the given object id from the cache */ public void invalidate(ObjectId id) { sharedCache.get().invalidate(keyPrefix.create(id)); }
/** * Checks whether a given {@link ObjectId} is already cached on this {@code ObjectCache} */ public boolean contains(ObjectId id) { return sharedCache.get().contains(keyPrefix.create(id)); }
/** * Prunes the given object id from the cache */ public void invalidate(ObjectId id) { sharedCache.get().invalidate(keyPrefix.create(id)); }
/** * Returns the cached object with the given id, if present, or {@code null} otherwise */ public @Nullable RevObject getIfPresent(ObjectId id) { return sharedCache.get().getIfPresent(keyPrefix.create(id)); } }
public void put(RevObject obj) { SharedCache cache = sharedCache.get(); CacheKey key = keyPrefix.create(obj.getId()); cache.put(key, obj); }
public @Test void testInvalidateAll() { final int L1Capacity = 10; SharedCache cache = SharedCache.build(L1Capacity, 16 * 1024 * 1024); List<RevObject> objects = createObjects(500); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> cache.put(repo2Id.create(o.getId()), o)); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo2Id.create(o.getId())))); cache.invalidateAll(); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Test void testL1WriteBack() { final int L1Capacity = 1000; cache = createCache(L1Capacity, maxCacheSizeBytes); List<RevObject> objects = createObjects(100); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Test void testL1WriteBack() { final int L1Capacity = 1000; SharedCache cache = SharedCache.build(L1Capacity, maxCacheSizeBytes); List<RevObject> objects = createObjects(100); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Before void before() { mockSharedCache = mock(SharedCache.class); cacheId1 = new CacheIdentifier(0); cacheId2 = new CacheIdentifier(1000); cache1 = new ObjectCache(() -> mockSharedCache, cacheId1); cache2 = new ObjectCache(() -> mockSharedCache, cacheId2); o1 = RevFeature.builder().addValue(0L).addValue("zero").build(); o2 = RevFeature.builder().addValue(1L).addValue("one").build(); k11 = cacheId1.create(o1.getId()); k21 = cacheId2.create(o1.getId()); k22 = cacheId2.create(o2.getId()); }
public @Test void testGetIfPresentEnsureL2Cache() throws Exception { Key k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); Future<?> l2Future = cache.put(k1, obj); assertNotNull(l2Future); l2Future.get(); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }
public @Test void testGetIfPresentEnsureL2Cache() throws Exception { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); Future<?> l2Future = cache.put(k1, obj); assertNotNull(l2Future); l2Future.get(); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }
public @Test void testGetIfPresentImmediately() { Key k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); assertNotNull(cache.put(k1, obj)); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }
public @Test void testPutIfAbsent() { Key k1 = repo1Id.create(obj.getId()); assertNotNull(cache.put(k1, obj)); assertNull(cache.put(k1, obj)); }
public @Test void testGetIfPresentImmediately() { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); assertNotNull(cache.put(k1, obj)); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }
public @Test void testPutIfAbsent() { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNotNull(cache.put(k1, obj)); assertNull(cache.put(k1, obj)); }
public @Test void testCacheDisabled() { cache = createCache(0, 0L); CacheKey k1 = repo1Id.create(obj.getId()); cache.put(k1, obj); assertFalse(cache.contains(k1)); assertEquals(0L, cache.sizeBytes()); }