Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 614

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Client-Server" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Reference Cache In Client-Server Mode</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../Resources/Code/prettify.js">
        </script>
        <script src="../Resources/Code/lang-vb.js">
        </script>
        <script src="../Resources/Code/jquery.min.js">
        </script>
        <script src="../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../index_CSH.html#client-server/reference_cache_in_client-server_mode.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../client-server.htm">Client-Server</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Reference Cache In Client-Server Mode</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1>Reference Cache In Client-Server Mode</h1>
        <p>db4o uses an <a href="../basics/indentity_concept/reference_cache.htm">object reference cache</a> for easy access to persistent objects during one transaction. In
client/server mode each client has its own reference cache, which helps to
achieve good performance. However it gets complicated, when different clients
work on the same object, as this object's cached value is used on each side. It
means, that even when the operations go serially, the object's value won't be
updated serially unless it is refreshed before each update.
</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Person personOnClient1 = QueryForPerson(client1);
Person personOnClient2 = QueryForPerson(client2);
Console.Write(QueryForPerson(client2).Name);

personOnClient1.Name = ("New Name");
client1.Store(personOnClient1);
client1.Commit();

// The other client still has the old data in the cache
Console.Write(QueryForPerson(client2).Name);

client2.Ext().Refresh(personOnClient2, int.MaxValue);

// After refreshing the date is visible
Console.Write(QueryForPerson(client2).Name);</pre>
            <div class="codesnippet-meta">ReferenceCacheExamples.cs: Reference cache in client server
			<div class="codedownload"><a href="../CodeExamples/clientserver/referencecache/Example-clientserver-referencecache-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim personOnClient1 As Person = QueryForPerson(client1)
Dim personOnClient2 As Person = QueryForPerson(client2)
Console.Write(QueryForPerson(client2).Name)

personOnClient1.Name = ("New Name")
client1.Store(personOnClient1)
client1.Commit()

' The other client still has the old data in the cache
Console.Write(QueryForPerson(client2).Name)

client2.Ext().Refresh(personOnClient2, Integer.MaxValue)

' After refreshing the date is visible
Console.Write(QueryForPerson(client2).Name)</pre>
            <div class="codesnippet-meta">ReferenceCacheExamples.vb: Reference cache in client server
			<div class="codedownload"><a href="../CodeExamples/clientserver/referencecache/Example-clientserver-referencecache-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>There are multiple strategies to deal with this.</p>
        <ul>
            <li value="1">If you client's are not updating the same object or it very unlikely that it happens, you don't need to take any action.</li>
            <li value="2">You can refresh objects as they are updated on all clients. However this need a lot of communication between the server and client. <a href="refreshing_objects.htm" target="" title="" alt="" class="MCXref" xrefformat="See &quot;{paratext}&quot;">See "Refreshing Objects"</a></li>
            <li value="3">You can do short unit of work on the client, to minimize the chance of outdated objects. </li>
        </ul>
        <h2>Clean Cache For Work</h2>
        <p>Often you don't want to refresh object by object. Instead you want to work with a clean cache. You can do this by using a separate 'session' on the client. This container brings its own cache with it. So you can create a new container which a clean cache.</p>
        <p>Note that open session on the client doesn't create a separate transaction. Instead it only creates a fresh cache. The transaction is always the same.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">using (IObjectContainer container = client.Ext().OpenSession())
{
    // do work
}
// Start with a fresh cache:
using (IObjectContainer container = client.Ext().OpenSession())
{
    // do work
}</pre>
            <div class="codesnippet-meta">ReferenceCacheExamples.cs: Clean cache for each unit of work
			<div class="codedownload"><a href="../CodeExamples/clientserver/referencecache/Example-clientserver-referencecache-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Using container As IObjectContainer = client.Ext().OpenSession()
    ' do work
End Using
' Start with a fresh cache:
Using container As IObjectContainer = client.Ext().OpenSession()
    ' do work
End Using</pre>
            <div class="codesnippet-meta">ReferenceCacheExamples.vb: Clean cache for each unit of work
			<div class="codedownload"><a href="../CodeExamples/clientserver/referencecache/Example-clientserver-referencecache-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <script type="text/javascript" src="../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>