Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (52 sloc) 2.17 KB
description
The persistence allow you to store any objects and retrieve thems at the next application launch.

Persistence

How to Use ?

Method to use in the fluent configuration builder: .UsePersistence()

Basic Example

This simple example show you how to setup persistence.

{% code-tabs %} {% code-tabs-item title="persistence-example.cs" %}

using (var tdb = new TypeDB.Core(Mode.Standalone)
.UsePersistence(new Persistence
{
    Location = Persistence.TemporaryLocation,
    Type = PersistenceType.Snapshot,
    Interval = TimeSpan.FromMinutes(1)
})
.Connect())
{
    var testdb = tdb.OpenDatabase("test", true)
    testdb.Set<string>("hello", "world");    // hello entity will be persisted
}

{% endcode-tabs-item %} {% endcode-tabs %}

The Types of Persistence

Type-DB has 3 modes of persistence and the default mode is PersistenceType.Node (no persistence).

PersistenceType.OnlyInvoke

This mode not store your entities when you call a specific method otherwise any persistence is executed, for perform a ponctual persistence you need to execute this method:

tdb.Configuration.Persistence.Invoke(tdb);    //where 'tdb' is your Instance of Typedb

PersistenceType.Snapshot

This mode is pretty useful to store entities regularly in the delay that you want, if you choose this mode you need to configure the interval with a TimeSpan object like this:

Interval = TimeSpan.FromMinutes(1)

PersistenceType.Iteration

This is the most heavy mode because it create a trigger for each method that you will call and perform a physical persistence accordingly.

You can also read about Triggers.

Location of the Persistence

By default Type-DB store all your entities in the Temp folder (on Windows this folder is C:\Users\you\AppData\Local\Temp) but you can choose this folder by setting the Location property:

Location = @"c:\my_folder"

You can also use some constant like:

  • Persistence.TemporaryLocation that is the default OS temp folder
  • Persistence.ApplicationDataLocation that is the AppData folder
  • Persistence.CurrentLocation that return the current execution folder
You can’t perform that action at this time.