Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0BE59C9C for ; Tue, 20 Mar 2012 14:44:26 +0000 (UTC) Received: (qmail 52942 invoked by uid 500); 20 Mar 2012 14:44:26 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 52910 invoked by uid 500); 20 Mar 2012 14:44:26 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 52902 invoked by uid 99); 20 Mar 2012 14:44:26 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2012 14:44:26 +0000 Received: from localhost (HELO mail-wi0-f175.google.com) (127.0.0.1) (smtp-auth username jonm, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2012 14:44:26 +0000 Received: by wibhn6 with SMTP id hn6so4304288wib.16 for ; Tue, 20 Mar 2012 07:44:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=6vc1rJpClIAwoCfT/DFfao0mPHpwubkW+bhXEBF2rks=; b=CyZ+QfZ0nATY6ZnrlhOLTBXH7Qz5mWx1n/98nQHBV7mALG3RwSP9eYDf546jNr2k2b UXI032mMtOGw8uGyq9XIf8Ah8OE+Gt7OhsH2mV6nGwNvWmaIpTCAT8gahSrVnZ7yf+aD cuEC9vnvZmmCpEA/him9cgks7p+gYwi6nb88ujLzDy5vJBVAnvAO4n6TyHRWQhJEB+fG 5cyMAPwLIMye/l6R9OGwg73/99Dum4hcj0+YLtr0bURYHnmT5CdyWpxdcHdQVOw/qa0D NAaL3C1G6LSUsVTEZeWn9ZyHDxnzqwAdsjxSIY5DMyGAUKhhRY5TDBAHU42c6mFJc9Gk DzTw== MIME-Version: 1.0 Received: by 10.50.11.137 with SMTP id q9mr140355igb.11.1332254663258; Tue, 20 Mar 2012 07:44:23 -0700 (PDT) Received: by 10.50.36.164 with HTTP; Tue, 20 Mar 2012 07:44:23 -0700 (PDT) X-Originating-IP: [75.149.106.130] In-Reply-To: References: Date: Tue, 20 Mar 2012 10:44:23 -0400 Message-ID: Subject: Re: Best practice for caching configuration From: Jon Moore To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=e89a8f50326cf431ff04bbadb545 X-Gm-Message-State: ALoCoQmth2JXtlaEXeHxARbZT24G5TTeUQecYAE+PVAU7tLe7cHVNj2lGHoS5WDKlU4ZrcflZQQW --e89a8f50326cf431ff04bbadb545 Content-Type: text/plain; charset=ISO-8859-1 Hi Alin, Actually, as it turns out, much of this information is already in the online docs: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html#storage Jon On Tue, Mar 20, 2012 at 8:19 AM, Jon Moore wrote: > Hi Alin, > > Great suggestion - I'll look into updating the documents for the 4.2 > release. > > Jon > > > On Sat, Mar 17, 2012 at 6:51 PM, Vasile Alin wrote: > >> would be great if http-cache will have these hints in its overview >> documents. >> >> Alin >> >> On 17 March 2012 17:50, Jon Moore wrote: >> >> > Hi Robert, >> > >> > Naturally, the ultimate answer is: it depends on your scenario! >> However, I >> > can perhaps provide some ways of thinking about your cache >> configuration. >> > >> > First, one of your choices will be which HttpCacheStorage >> implementation(s) >> > you want to use; there are 3 supported in the distribution: >> > 1. an in-memory cache; this is the default implementation if you don't >> > specify an alternative >> > 2. an EhCache backend; this can be used to build a tiered in-memory and >> > on-disk cache, and the on-disk can be configured to persist across >> > application invocations >> > 3. a memcached backend; this can be used either to keep your JVM heap >> size >> > smaller by keeping the cache memory out-of-process, or as a shared >> > memcached pool for a cluster of application servers, for example >> > >> > Now, because the CachingHttpClient is a decorator, you can actually use >> > multiple of these at the same time by wrapping them one inside the >> other. >> > So, for example, you can have a L1 in-memory cache backed by a L2 >> EhCache >> > that spills to disk. >> > >> > In all cases, you will want to be concerned with the total storage >> > resources you want to allocate to the cache; EhCache and memcached have >> > their own configuration for this, but you may want to tweak this for the >> > in-memory cache if that's what you use. One thing to look at is the >> maximum >> > response body size that you'll cache, which currently defaults to 8KB; >> if >> > you plan on caching responses than that, you'll need to increase this >> > setting via CacheConfig#setMaxObjectSizeBytes(). >> > >> > If your server(s) use the 'stale-while-revalidate' Cache-Control >> directive, >> > then you may want to play with >> > CacheConfig#setAsynchronousWorkerIdleLifetimeSecs(), >> > CacheConfig#setAsynchronousWorkersCore(), >> > CacheConfig#setAsynchronousWorkersMax(), and >> > CacheConfig#setRevalidationQueueSize(), all of which basically control >> an >> > underlying thread pool configuration to handle the background validation >> > requests. These have "safe" defaults, so you may not need to tweak these >> > until you get into performance tuning. >> > >> > Finally, if your origin servers don't set proper Cache-Control headers >> but >> > you want to cache the responses anyway, you may want to change >> > CacheConfig#setHeuristicDefaultLifetime(). Another option for this is to >> > write another decorator to modify Cache-Control headers on specific >> > responses that come through, wired up between the CachingHttpClient and >> the >> > "real" underlying HttpClient. >> > >> > That said, if you just drop an unconfigured CachingHttpClient in, for >> say, >> > an API client that gets relatively small, but cacheable responses, you >> > should hopefully see some immediate benefit just from the in-memory >> cache. >> > >> > Hope that helps, >> > Jon >> > >> > On Sat, Mar 17, 2012 at 10:21 AM, Robert Naczinski < >> > robert.naczinski@googlemail.com> wrote: >> > >> > > Hello, >> > > >> > > I want my application use cache, as shown below >> > > >> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html >> > . >> > > >> > > Does anyone know the best settings or recommendations for the >> > > configuration of the cache? >> > > >> > > Regards, >> > > >> > > Robert >> > > >> > > --------------------------------------------------------------------- >> > > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org >> > > For additional commands, e-mail: httpclient-users-help@hc.apache.org >> > > >> > > >> > >> > > --e89a8f50326cf431ff04bbadb545--