This repository was archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.html
50 lines (36 loc) · 2.18 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<h1>Fluidity.Raven.Lock</h1>
<p>A simple way, without server change, to allow pessimistic locks in RavenDB, using the current optimistic lock feature.</p>
<p>It's not a perfect way but if the Ayende put this in Raven, then he could optimize it in a better way.</p>
<h2>Install by Nuget</h2>
<p><code>Install-Package Fluidity.Raven.Lock</code></p>
<h2>Usage</h2>
<p><code>C#<br />
using (var locker = documentSession.Lock("MyLockName"))<br />
{<br />
// do some work<br />
}<br />
</code></p>
<p>You can configure a timeout to grab the lock, so if it fails to lock in the time it will raise a <code>System.TimeoutException</code>.</p>
<p>Because the lock is <strong>stored on the server</strong> and <strong>managed by the client</strong>, it was necessary to create some security way to not lock forever with a key, so each lock has an expiration time defined.</p>
<p>If another lock tries to grant his way by using a key and it fails for some tries, it will check if the lock is an expired lock, then delete it and try again to grab the lock.</p>
<p>You can set the timeout or the lifetime of the lock when creating it, by using some of the methods signatures ahead:</p>
<ul>
<li><code>ILocker Lock(this IDocumentSession documentSession, string lockName)</code>;</li>
<li><code>ILocker Lock(this IDocumentSession documentSession, string lockName, TimeSpan timeout)</code>;</li>
<li><code>ILocker Lock(this IDocumentSession documentSession, string lockName, TimeSpan timeout, TimeSpan lifetime)</code>;</li>
</ul>
<p><strong>Important</strong></p>
<ul>
<li>The default timeout for waiting to lock is 30 seconds;</li>
<li>The default lifetime of a lock is 1 minute.</li>
<li>If for some reason, you need to create a lock and execute some undeterministic algorithm, and you don't want to increase the lifetime of the lock so much, you can use this:</li>
</ul>
<p><code>C#<br />
using (var locker = documentSession.Lock("MyLockName"))<br />
{<br />
// do some work<br />
locker.Renew(TimeSpan.FromMinutes(1)); // expanding the lifetime in more 1 minute from now<br />
// more work<br />
locker.Renew(TimeSpan.FromMinutes(1)); // expanding the lifetime in more 1 minute from now<br />
}<br />
</code></p>