X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C0F14D7DCE for ; Sun, 28 Aug 2005 11:14:07 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90429-04 for ; Sun, 28 Aug 2005 14:14:05 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id D9189D7D7D for ; Sun, 28 Aug 2005 11:14:04 -0300 (ADT) Received: from [192.168.1.100] ([24.202.23.128]) by VL-MO-MR007.ip.videotron.ca (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0ILX00A7SRHA93@VL-MO-MR007.ip.videotron.ca> for pgsql-jdbc@postgresql.org; Sun, 28 Aug 2005 10:12:46 -0400 (EDT) Date: Sun, 28 Aug 2005 10:14:03 -0400 From: David Gagnon Subject: Re: implementing asynchronous notifications PLEASE CONFIRM MY In-reply-to: <43120302.9030509@menelic.com> To: "Arcadius A." , pgsql-jdbc@postgresql.org Message-id: <4311C6AB.1020607@siunik.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) References: <4265A05C.6050302@opencloud.com> <42667C72.9070708@siunik.com> <4266E296.6050105@opencloud.com> <4308AF3A.2070400@siunik.com> <43120302.9030509@menelic.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.026 required=5 tests=[AWL=0.026] X-Spam-Level: X-Archive-Number: 200508/187 X-Sequence-Number: 13756 Hi , Thanks for your answer, see my answer below.. > David Gagnon wrote: > >> Hi all, >> >> I have a java web application connected to a postgresql DB (of >> course :-)). I create a bunch of cache in my web Application and I >> need postgresql to inform the application of row update and delete. >> I think this is a common behavior when we cache data in the >> application and use stored procedure to update data. >> I saw this thread (See below) a while ago but I'm not sure a this is >> the best way to solve my problem. I think there is 3 possibilities >> to solve this problem: >> >> #1: Having rules/trigger on update and delete that create >> notification. On the java server I need a thread to read the >> notification and update the caches in the system accordingly. >> >> #2: Having rules/trigger on update and delete that write a line into >> a table. On the java server I need a thread to read the table and >> update the caches in the system accordingly. >> >> #3: Having rules/trigger on update and delete that call a CALLBACK >> function that goes directly to the server... and update the cache >> directly. >> >> #4: Any other idea ? >> >> >> For #1: Is that reliable? 100% full prove. I must not loose >> notifications... because my cache wont be in synch >> >> For #2: Seem the best way to do it... Is there a way to do it to >> reduce performance impact ? >> >> For #3: Don't think it's implemented yet ... am I wrong? >> >> >> Thanks for your help pointing me the best implementation to solve my >> problem >> >> Best Regards ! >> >> > > However I do not know your exact requirement, if I were to solve such > a problem, I would not try to put any overhead on the DB server; after > all, the purpose of caching is to give a brake to the DBServer. > > In fact, the easiest way to have the cache in sync with the DB is to > have a kind of Facade , a unique class, with static methods for > reading/writing data for both the cache and the DB. > > Using a single class for reading/writing , you won't need the DB to > notify you of changes since all call go through your facade, that > means that you know when things are being changed and can take action. > > However, your requirements my be different. > > > Regards. \ I already have a facade I my application. The problem comes when some data intensive stored procedure modify table.... If I modify a client table, an account receivable table ... I need to inform the application. So no choice I need to inform my application. If I use a kind of polling from the application I may have invalid data in my application.. The big problem is that when a user launch a stored procedure.. chance are that he will consult the other data right after the completion of the stored procedure. If data have not been updated in the cache I will display invalid data :-( I think that it's a common problem when you have a web application that use a caching mechanism and use stored procedure. Without an apdapted notification framework you are force use some alternative solution that probably have important performance impact. I think the best solution will be to have the LISTEN/NOTIFY support an arbitrary string. I saw this have been put in the TODO list. Is there any plan to put that soon ? Sorry I don't have the knowledge to do it my self :-( Regards /David > >