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.min.html
1 lines (1 loc) · 2.1 KB
/
README.min.html
1
<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>