@Test public void testCacheHit() { HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient", ClientOptions.create() .withConfigurationBasedServerList("localhost:12345") .withMaxAutoRetriesNextServer(1)); final String content = "from cache"; final String cacheKey = "somekey"; HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test") .withCacheProvider(cacheKey, new CacheProvider<ByteBuf>(){ @Override public Observable<ByteBuf> get(String key, Map<String, Object> vars) { if (key.equals(cacheKey)) { try { return Observable.just(Unpooled.buffer().writeBytes(content.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { return Observable.error(e); } } else { return Observable.error(new Exception("Cache miss")); } } }).withUriTemplate("/") .withMethod("GET").build(); RibbonRequest<ByteBuf> request = template .requestBuilder().build(); String result = request.execute().toString(Charset.defaultCharset()); assertEquals(content, result); }
public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract);  }