LruCacheProvider createProvider(final String name, final String capacity, int defaultCapacity) { Module module = new AbstractModule() { @Override public void configure() { binder().bindConstant() .annotatedWith(Names.named("shindig.cache.lru." + name + ".capacity")) .to(capacity); } }; Injector injector = Guice.createInjector(module); return new LruCacheProvider(injector, defaultCapacity); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@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")); }
LruCacheProvider createProvider(final String name, final String capacity, int defaultCapacity) { Module module = new AbstractModule() { @Override public void configure() { binder().bindConstant() .annotatedWith(Names.named("shindig.cache.lru." + name + ".capacity")) .to(capacity); } }; Injector injector = Guice.createInjector(module); return new LruCacheProvider(injector, defaultCapacity); }
@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")); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
LruCacheProvider createProvider(final String name, final String capacity, int defaultCapacity) { Module module = new AbstractModule() { @Override public void configure() { binder().bindConstant() .annotatedWith(Names.named("shindig.cache.lru." + name + ".capacity")) .to(capacity); } }; Injector injector = Guice.createInjector(module); return new LruCacheProvider(injector, defaultCapacity); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
LruCacheProvider createProvider(final String name, final String capacity, int defaultCapacity) { Module module = new AbstractModule() { @Override public void configure() { binder().bindConstant() .annotatedWith(Names.named("shindig.cache.lru." + name + ".capacity")) .to(capacity); } }; Injector injector = Guice.createInjector(module); return new LruCacheProvider(injector, defaultCapacity); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
LruCacheProvider createProvider(final String name, final String capacity, int defaultCapacity) { Module module = new AbstractModule() { @Override public void configure() { binder().bindConstant() .annotatedWith(Names.named("shindig.cache.lru." + name + ".capacity")) .to(capacity); } }; Injector injector = Guice.createInjector(module); return new LruCacheProvider(injector, defaultCapacity); }
@Test public void testInvalidateUrl() throws Exception { cache.addResponse(new HttpRequest(URI), CACHEABLE); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); service.invalidateApplicationResources( ImmutableSet.of(URI), appxToken); assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@SuppressWarnings("unchecked") public <K, V> Cache<K, V> createCache(String name) { int capacity = getCapacity(Preconditions.checkNotNull(name)); Cache<K, V> cache = (Cache<K, V>) caches.get(name); if (cache == null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating cache named " + name); } cache = new LruCache<K, V>(capacity); caches.put(name, cache); } return cache; } }
@Test public void defaultCapacityForNamedCache() throws Exception { LruCacheProvider provider = new LruCacheProvider(10); assertEquals(10, getCache(provider, "foo").capacity); }
@Test public void testFetchContentWithMarker() throws Exception { oauth.httpResponse = CACHEABLE; // First entry added to cache is unmarked HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for OwnerX. Next entry will have owner mark service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1"). create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for ViewerX. Next entry will have both owner and viewer mark service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2"). create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT2", httpResponse.getResponseAsString()); assertEquals("o=1;v=2;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
@Before public void setUp() throws Exception { cajaCssParser = new CajaCssParser(); cajaCssParser.setCacheProvider(new LruCacheProvider(10)); }
@Test public void testFetchContentWithMarker() throws Exception { oauth.httpResponse = CACHEABLE; // First entry added to cache is unmarked HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for OwnerX. Next entry will have owner mark service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1"). create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for ViewerX. Next entry will have both owner and viewer mark service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2"). create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT2", httpResponse.getResponseAsString()); assertEquals("o=1;v=2;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }