Return-Path: Delivered-To: apmail-cayenne-dev-archive@www.apache.org Received: (qmail 29619 invoked from network); 16 Sep 2008 14:40:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Sep 2008 14:40:27 -0000 Received: (qmail 63527 invoked by uid 500); 16 Sep 2008 14:40:24 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 63509 invoked by uid 500); 16 Sep 2008 14:40:24 -0000 Mailing-List: contact dev-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list dev@cayenne.apache.org Received: (qmail 63498 invoked by uid 99); 16 Sep 2008 14:40:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Sep 2008 07:40:24 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of blacknext@gmail.com designates 64.233.182.187 as permitted sender) Received: from [64.233.182.187] (HELO nf-out-0910.google.com) (64.233.182.187) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Sep 2008 14:39:26 +0000 Received: by nf-out-0910.google.com with SMTP id g16so1494906nfd.2 for ; Tue, 16 Sep 2008 07:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=yDSJKsq9z0bDx5kzCQwmIt2W+Z/XMvwegQCOX9ShjVQ=; b=XcJH87SQAUXQ8mXWXjT0+pz2PRYc2TA8sdX8JvAzqbePJDkf2FaMKv53WQrZ5Awnzh D+d2Ln0COj0ZSRR+XKwZjXjqxCuwK4KgEjsvUQXeW80OChTe4BJY+i5gYp5TPaCTB8xG hLASNi7Q0DkAYnMIWFZmyFY3s02WR2grVLCzo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=cZ10lG2F68V6Ht7RtxmQD89RnNwb+XeqRkGjzaBy2PIMzJG6E1g3wg9vTCi0s6bMJk OO3MNjolK9qKQaLT6eS0TbeJUOZBccWJvy0Sp0D8gpZ2eO43YaqFkmP8cqB7lmUjzzGn ikfzY1bfesk5AcZ6i+fyJ5B9ntmSQHK/LOiA8= Received: by 10.187.212.1 with SMTP id o1mr136007faq.30.1221575997631; Tue, 16 Sep 2008 07:39:57 -0700 (PDT) Received: by 10.187.165.9 with HTTP; Tue, 16 Sep 2008 07:39:57 -0700 (PDT) Message-ID: Date: Tue, 16 Sep 2008 10:39:57 -0400 From: "Michael Gentry" To: dev@cayenne.apache.org Subject: Re: svn commit: r695898 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java In-Reply-To: <6B1BB9FD-783B-4FAE-82EC-09911FC1699B@objectstyle.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080916142412.91DCF2388A08@eris.apache.org> <6B1BB9FD-783B-4FAE-82EC-09911FC1699B@objectstyle.org> X-Virus-Checked: Checked by ClamAV on apache.org So there is no good way of caching parsed expressions, then? Thanks! On Tue, Sep 16, 2008 at 10:36 AM, Andrus Adamchik wrote: > Also (c) (related to my "emeddable" note) - in an environment like J2EE, > where there are layers upon layers of explicit and implicit containers > between the VM and the application code, having a static object storage > buried in a framework is a bad practice - it prevents the container layers > from performing their functions of isolating "contexts" for various users > (whatever those contexts might be). > > Andrus > > On Sep 16, 2008, at 5:30 PM, Andrus Adamchik wrote: > >> -1. Unmanaged static caches are bad, especially in an embeddable framework >> like Cayenne. This is (a) a potential memory leak and (b) a potential >> synchronization nightmare (Expression is not immutable and can be modified >> by the caller). >> >> Andrus >> >> >> On Sep 16, 2008, at 5:24 PM, mgentry@apache.org wrote: >> >>> Author: mgentry >>> Date: Tue Sep 16 07:24:11 2008 >>> New Revision: 695898 >>> >>> URL: http://svn.apache.org/viewvc?rev=695898&view=rev >>> Log: >>> Updated Expression.fromString to cache the parsed expressions instead of >>> re-parsing them every time. >>> >>> Modified: >>> >>> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java >>> >>> Modified: >>> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java >>> URL: >>> http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java?rev=695898&r1=695897&r2=695898&view=diff >>> >>> ============================================================================== >>> --- >>> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java >>> (original) >>> +++ >>> cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java >>> Tue Sep 16 07:24:11 2008 >>> @@ -26,6 +26,7 @@ >>> import java.io.StringWriter; >>> import java.util.Collection; >>> import java.util.Collections; >>> +import java.util.HashMap; >>> import java.util.LinkedList; >>> import java.util.List; >>> import java.util.Map; >>> @@ -119,21 +120,36 @@ >>> >>> protected int type; >>> >>> + private static Map expressionCache = >>> + Collections.synchronizedMap(new HashMap>> Expression>(32)); >>> + >>> /** >>> * Parses string, converting it to Expression. If string does not >>> represent a >>> * semantically correct expression, an ExpressionException is thrown. >>> * >>> * @since 1.1 >>> */ >>> - // TODO: cache expression strings, since this operation is pretty >>> slow >>> public static Expression fromString(String expressionString) { >>> if (expressionString == null) { >>> throw new NullPointerException("Null expression string."); >>> } >>> >>> - Reader reader = new StringReader(expressionString); >>> + // Retrieve, if possible, the expression from the cache. >>> + Expression expression = expressionCache.get(expressionString); >>> + >>> + // If the expression was cached, return it immediately without >>> parsing. >>> + if (expression != null) >>> + return expression; >>> + >>> + // Couldn't find expression, parse, cache, and return it. >>> try { >>> - return new ExpressionParser(reader).expression(); >>> + Reader reader = new StringReader(expressionString); >>> + >>> + expression = new ExpressionParser(reader).expression(); >>> + >>> + expressionCache.put(expressionString, expression); >>> + >>> + return expression; >>> } >>> catch (ParseException ex) { >>> throw new ExpressionException(ex.getMessage(), ex); >>> >> >> > >