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 94D499021 for ; Sat, 17 Mar 2012 22:52:10 +0000 (UTC) Received: (qmail 26452 invoked by uid 500); 17 Mar 2012 22:52:10 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 26417 invoked by uid 500); 17 Mar 2012 22:52:10 -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 26409 invoked by uid 99); 17 Mar 2012 22:52:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Mar 2012 22:52:10 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of alinachegalati@gmail.com designates 74.125.82.179 as permitted sender) Received: from [74.125.82.179] (HELO mail-we0-f179.google.com) (74.125.82.179) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Mar 2012 22:52:02 +0000 Received: by werg1 with SMTP id g1so5011706wer.10 for ; Sat, 17 Mar 2012 15:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ak1asYy3Fsu+0PnPSKz5ZSWINufc5ZNNuu8L8Sm5TEc=; b=zZzMZ/f5crFHpS5XruuCTUNpr7OHqArlDT1+bhr01QiHi66f4AnwF0YcWpRlT71rYE pqErxJeuM6KwWATcGWX792a68gUskjmvEWg78TUKeDMUnMK8wcFe2sqZkvepCB5bPsnP K7UgGiiwG2QVDmWl2bStqhJL0jnDw6vvfGjxAV5Fq4FlGCGnr9PVR1cPFn3zkaVyJBNi LrLcYdFcMpTHBRr+nJCgvQ6WEqr8KhQp/rLQrkBLxzntXNm2euWrOqsTuvIreIMBpWNM EmRjlIcT5Sv1sjtdTG09LE6kpSYJozWmu/SXmv1eN5CORiOBxRVuYx+HMOYllWKcFpBc wscg== MIME-Version: 1.0 Received: by 10.180.93.4 with SMTP id cq4mr8592068wib.21.1332024702019; Sat, 17 Mar 2012 15:51:42 -0700 (PDT) Received: by 10.216.192.36 with HTTP; Sat, 17 Mar 2012 15:51:41 -0700 (PDT) In-Reply-To: References: Date: Sun, 18 Mar 2012 00:51:41 +0200 Message-ID: Subject: Re: Best practice for caching configuration From: Vasile Alin To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=f46d043c8068322a2c04bb782b4a X-Virus-Checked: Checked by ClamAV on apache.org --f46d043c8068322a2c04bb782b4a Content-Type: text/plain; charset=ISO-8859-1 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 > > > > > --f46d043c8068322a2c04bb782b4a--