@Override protected HttpResponse getResponseImpl(String key) { return cache.getElement(key); }
@Override protected HttpResponse getResponseImpl(String key) { return cache.getElement(key); }
public Tree get(String expression) { return resolvedTreeCache.getElement(expression); }
public Tree get(String expression) { return resolvedTreeCache.getElement(expression); }
@Override protected HttpResponse getResponseImpl(String key) { return cache.getElement(key); }
public Tree get(String expression) { return resolvedTreeCache.getElement(expression); }
public Tree get(String expression) { return resolvedTreeCache.getElement(expression); }
public Tree get(String expression) { return resolvedTreeCache.getElement(expression); }
public List<? extends Job> fetch(Key k) { if (!(k instanceof ModuleCacheKey)) { return null; } ImmutableList<Job> cachedJobs = backingCache.getElement((ModuleCacheKey) k); if (cachedJobs == null) { return null; } if (cachedJobs.isEmpty()) { return cachedJobs; } return cloneJobs(cachedJobs); }
/** * Retrieve an element from the cache by key. If there is no such element * for that key in the cache, or if the element has timed out, null is returned. * @param key Key whose element to look up. * @return Element in the cache, if present and not timed out. */ public CachedObject<V> getElement(K key) { V value = cache.getElement(key); if (value == null) { return null; } Long expiration = expirationTimes.get(value); if (expiration == null) { return null; } return new CachedObject<V>(value, expiration < timeSource.currentTimeMillis()); }
@Test public void testInvalidateUsers() throws Exception { service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appxToken); service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appyToken); assertEquals(4, cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME).getSize()); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:1")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:2")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:1")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:2")); }
@Test public void testInvalidateUsers() throws Exception { service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appxToken); service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"), appyToken); assertEquals(4, cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME).getSize()); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:1")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppX:2")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:1")); assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME) .getElement("INV_TOK:AppY:2")); }
@Test public void getNamedCache() throws Exception { Cache<String, String> cache = defaultProvider.createCache("testcache"); Cache<String, String> cache2 = defaultProvider.createCache("testcache"); Assert.assertNotNull(cache); Assert.assertEquals(cache, cache2); Assert.assertNull(cache.getElement("test")); cache.addElement("test", "value1"); Assert.assertEquals("value1", cache.getElement("test")); cache.removeElement("test"); Assert.assertNull(cache.getElement("test")); Assert.assertEquals(cache.getCapacity(), cache2.getCapacity()); Assert.assertEquals(cache.getSize(), cache2.getSize()); }
@Test public void addResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponse("response"); httpCache.addResponse(request, response); String key = httpCache.createKey(request); assertEquals(response, cache.getElement(key)); }
@Test public void getNamedCache() throws Exception { Cache<String, String> cache = defaultProvider.createCache("testcache"); Cache<String, String> cache2 = defaultProvider.createCache("testcache"); Assert.assertNotNull(cache); Assert.assertEquals(cache, cache2); Assert.assertNull(cache.getElement("test")); cache.addElement("test", "value1"); Assert.assertEquals("value1", cache.getElement("test")); cache.removeElement("test"); Assert.assertNull(cache.getElement("test")); Assert.assertEquals(cache.getCapacity(), cache2.getCapacity()); Assert.assertEquals(cache.getSize(), cache2.getSize()); }
@Test public void getNamedCache() throws Exception { Cache<String, String> cache = defaultProvider.createCache("testcache"); Cache<String, String> cache2 = defaultProvider.createCache("testcache"); Assert.assertNotNull(cache); Assert.assertEquals(cache, cache2); Assert.assertNull(cache.getElement("test")); cache.addElement("test", "value1"); Assert.assertEquals("value1", cache.getElement("test")); cache.removeElement("test"); Assert.assertNull(cache.getElement("test")); Assert.assertEquals(cache.getCapacity(), cache2.getCapacity()); Assert.assertEquals(cache.getSize(), cache2.getSize()); }
@Test public void getNamedCache() throws Exception { Cache<String, String> cache = defaultProvider.createCache("testcache"); Cache<String, String> cache2 = defaultProvider.createCache("testcache"); Assert.assertNotNull(cache); Assert.assertEquals(cache, cache2); Assert.assertNull(cache.getElement("test")); cache.addElement("test", "value1"); Assert.assertEquals("value1", cache.getElement("test")); cache.removeElement("test"); Assert.assertNull(cache.getElement("test")); Assert.assertEquals(cache.getCapacity(), cache2.getCapacity()); Assert.assertEquals(cache.getSize(), cache2.getSize()); } }
@Test public void getNamedCache() throws Exception { Cache<String, String> cache = defaultProvider.createCache("testcache"); Cache<String, String> cache2 = defaultProvider.createCache("testcache"); Assert.assertNotNull(cache); Assert.assertEquals(cache, cache2); Assert.assertNull(cache.getElement("test")); cache.addElement("test", "value1"); Assert.assertEquals("value1", cache.getElement("test")); cache.removeElement("test"); Assert.assertNull(cache.getElement("test")); Assert.assertEquals(cache.getCapacity(), cache2.getCapacity()); Assert.assertEquals(cache.getSize(), cache2.getSize()); } }
@Test public void addResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponse("response"); httpCache.addResponse(request, response); String key = httpCache.createKey(request); assertEquals(response, cache.getElement(key)); }
@Test public void addResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI); HttpResponse response = new HttpResponse("response"); httpCache.addResponse(request, response); String key = httpCache.createKey(request); assertEquals(response, cache.getElement(key)); }