-
Notifications
You must be signed in to change notification settings - Fork 5
/
Locking.cs
37 lines (28 loc) · 959 Bytes
/
Locking.cs
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
// This is public domain Metalama sample code.
using Metalama.Patterns.Caching.Aspects;
using System;
using System.Threading;
namespace Doc.Locking
{
public sealed class CloudService : IDisposable
{
// We use barriers to make sure we wait long enough.
private readonly Barrier _withoutLockBarrier = new( 2 );
[Cache( ProfileName = "Locking" )]
public byte[] ReadFileWithLock( string path )
{
Console.WriteLine( "Doing some very hard work." );
Thread.Sleep( 50 );
return new byte[32];
}
[Cache]
public byte[] ReadFileWithoutLock( string path )
{
Console.WriteLine( "Doing some very hard work." );
// Simulate a long-running operation.
this._withoutLockBarrier.SignalAndWait();
return new byte[32];
}
public void Dispose() => this._withoutLockBarrier.Dispose();
}
}