Link to home
Start Free TrialLog in
Avatar of jlalande
jlalande

asked on

Does Notes cache its NotesDocument COM objects?

I am using the Notes COM toolkit to do contact lookups.  The issue I am having is that if I make a change to a contact in Notes (edit a phone number, etc), then retrieve the updated NotesDocument, the updates are not present.

Does Notes cache these objects?  And if so, is there a way to force the NotesDocument to refresh itself?
Avatar of marilyng
marilyng

Apologies if this is a stupid question, but can you clarify what you mean by Notes COM toolkit?  Are you writing an external program using Visual Studio, C, etc. that is opening  the names.nsf database on a local client or server? (which one).

Are you using the COM objects to search through a view to grab a document, and are you accessign that document directly, or are you using the view column to get the results.

Reason I ask is stepping through a view, and getting view column results might be delayed for a number of reasons:  The public directory, names.nsf, is usually replicated to many servers, and the view indexes may not be immediately refreshed.  However, document changes should be current.

The same may hold true for the contacts residing in the pernames.nsf (local address book).  The document may be updated immediately, but the view index may be delayed.

That being said, front end changes to a Notes document are usually refreshed when saved.   Commands like, @DBLookup, use a Cache/NoCache option, when searching for values.  If invoked, then the lookup will cache the results to avoid searching for newer items.

It really depends on what commands you are using.   I found if I don't destroy variables and recreate them, then the external program will cache old values.  It might help if you post a bit of code. :)
Avatar of jlalande

ASKER

The Lotus Notes COM Toolkit is simply another toolkit that IBM provides for custom integration with Notes.  However, it is no longer available nor supported.  We are currently using the C Toolkit for new development, but still have key portions of code dependent on the COM Toolkit.

Our development is in C#, but the following VBScript shows what we are doing:

set session = CreateObject("Lotus.NotesSession.7.0")
session.Initialize
set db = session.GetDatabase("", "C:\Program Files\lotus\notes\data\Names.nsf", true)
if not db.IsOpen then
  db.Open
end if
set doc = db.GetDocumentByUNID("5F76B8E5528B01B1862572AA005E0B33")
itemList = doc.GetItemValue("OfficePhoneNumber")
WScript.Echo(itemList(0))
set doc = db.GetDocumentByUNID("5F76B8E5528B01B1862572AA005E0B33")
itemList = doc.GetItemValue("OfficePhoneNumber")
WScript.Echo(itemList(0))

A test contact is created that has a UNID of "5F76B8E5528B01B1862572AA005E0B33".  The UNID cannot be set; I had to write another script to extract this value.  If the script is run from Explorer (double-click), a message box displaying the office phone number.  While the message is displayed, I can return to Notes, update the office phone and save the change.  If I return to the message, click OK, the NotesDocument is refetched but the office phone does not show the change.

I have tried refetching the database as well with no change.  Re-initializing the NotesSession object does work, however, I am concerned about the cost.  But it looks like there's no other way.
So, when you destroy the session, the program releases its handles and cached information?  What we normally do at the end of the script is destroy the handles, like doc, so it doesn't cache and return the previous value.   Question, are you declaring the variables?  (Early vs. late binding?)

A thought, the local client might cache more than the server.  I would have to try this to see if it does.  Generally, I've never had to hit a local client for data.  I usually stick to hitting the server, which is probably why I haven't run into this.  Mayne one of the more savvy C experts will pitch in. :)

Will try and get back to you.

Yes, recreating the session object gets the updated data.  It looks like we may have to do this for our solution.  We are testing this now.

Apparently, the approach used where the session is instantiated and used throughout the application session is not the correct approach.
ASKER CERTIFIED SOLUTION
Avatar of marilyng
marilyng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It turns out that this is certainly correct and our solution works around this by recreating the session.