Sophie

Sophie

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

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="Configuration|File Configuration|Storage" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>CachingStorage	</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="../../../SkinSupport/MadCapAll.js">
        </script>
        <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>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../index_CSH.html#configuration/file/storage/cachingstorage.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../configuration.htm">Configuration</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../../file_configuration.htm">File Configuration</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../storage.htm">Storage</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">CachingStorage	</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><a name="kanchor48"></a>CachingStorage</h1>
        <p>The CachingStorage
is db4o's default storage. The default
implementation uses the LRU/Q2 caching mechanism to reduce disk access times and to
improve performance. The cache is characterized by the amount of pages that
can be utilized and the page size. The multiplication of these two parameters
gives the maximum cache size that can be used.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
IStorage fileStorage = new FileStorage();
IStorage cachingStorage = new CachingStorage(fileStorage, 128, 1024);
configuration.File.<span class="MCPopup"><a href="javascript:void(0);" class="MCPopupSpot" onclick="FMCPopup( event, this ); return false;" MadCap:src="../storage.htm">Storage<img style="border: none;margin-left: 5px;" src="../../../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../../../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../../SkinSupport/ExpandingOpen.gif' ); }" /></a></span> = cachingStorage;
IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o");</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.cs: Using a caching storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-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 configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
Dim fileStorage As IStorage = New FileStorage()
Dim cachingStorage As IStorage = New CachingStorage(fileStorage, 128, 1024)
configuration.File.Storage = cachingStorage
Dim container As IObjectContainer = Db4oEmbedded.OpenFile(configuration, "database.db4o")</pre>
            <div class="codesnippet-meta">IOConfigurationExamples.vb: Using a caching storage
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-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>
        <h2>Page Count and Page Size</h2>
        <p>The CachingStorage takes two parameters, the page count and the page size. Bigger page size means faster handling of information as there is no need to switch between pages for longer. On the
other hand a bigger page size will mean higher memory consumption, as memory will
be reserved for the whole page size, when the page is needed. Modify
these values and run performance tests to find the best
performance/memory consumption combination for your system. The default values
are the following:</p>
        <p>Page count = 64 
Page size = 1024KB</p>
        <p>This gives a total of 64 KB of cache memory. </p>
        <h2>Caching Type</h2>
        <p>By default db4o uses a LRU/Q2 caching strategy. You can more about the LRU/Q2 cache on the Internet or you can look for the concrete implementation in db4o source code: LRU2QCache, LRU2QXCache and LRUCache. The LRU2QCache is a
simplified implementation of the 2 Queue algorithm described here:<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.2641">http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1..34.2641</a></p>
        <p>It's possible to exchange the cache-type. Inherit from the CachingStorage-class and overwrite the new cache method. There you return you're caching implementation. For example use a simple LRU-Cache.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">public class LRUCachingStorage : CachingStorage {
    private readonly int pageCount;

    public LRUCachingStorage(IStorage storage):base(storage) {
        this.pageCount = 128;
    }

    public LRUCachingStorage(IStorage storage, int pageCount, int pageSize)
        : base(storage, pageCount, pageSize)
    {
        this.pageCount = pageCount;
    }

    protected override ICache4 NewCache()
    {
        return CacheFactory.NewLRUCache(pageCount);
    }
}</pre>
            <div class="codesnippet-meta">LRUCachingStorage.cs: Exchange the cache-implementation
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-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">Public Class LRUCachingStorage
    Inherits CachingStorage
    Private ReadOnly pageCount As Integer

    Public Sub New(ByVal storage As IStorage)
        MyBase.New(storage)
        Me.pageCount = 128
    End Sub

    Public Sub New(ByVal storage As IStorage, ByVal pageCount As Integer, ByVal pageSize As Integer)
        MyBase.New(storage, pageCount, pageSize)
        Me.pageCount = pageCount
    End Sub

    Protected Overrides Function NewCache() As ICache4
        Return CacheFactory.NewLRUCache(pageCount)
    End Function
End Class</pre>
            <div class="codesnippet-meta">LRUCachingStorage.vb: Exchange the cache-implementation
			<div class="codedownload"><a href="../../../CodeExamples/configuration/io/Example-configuration-io-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>&#160;</p>
        <script type="text/javascript" src="../../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>