Skip to content

Commit 3606455

Browse files
committed
Add comments to private fields and methods
1 parent be9bcdc commit 3606455

File tree

9 files changed

+212
-8
lines changed

9 files changed

+212
-8
lines changed

libraries/src/AWS.Lambda.Powertools.Idempotency/AWS.Lambda.Powertools.Idempotency.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,4 @@
4343
<None Include="../../AWSLogo128x128.png" Pack="true" Visible="false" PackagePath="" />
4444
</ItemGroup>
4545

46-
<ItemGroup>
47-
<Folder Include="Output\" />
48-
</ItemGroup>
49-
5046
</Project>

libraries/src/AWS.Lambda.Powertools.Idempotency/Idempotency.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,27 @@ public sealed class Idempotency
3838
/// </summary>
3939
public BasePersistenceStore PersistenceStore { get; private set; } = null!;
4040

41+
/// <summary>
42+
/// Idempotency Constructor
43+
/// </summary>
44+
/// <param name="powertoolsConfigurations"></param>
4145
internal Idempotency(IPowertoolsConfigurations powertoolsConfigurations)
4246
{
4347
powertoolsConfigurations.SetExecutionEnvironment(this);
4448
}
45-
49+
/// <summary>
50+
/// Set Idempotency options
51+
/// </summary>
52+
/// <param name="options"></param>
4653
private void SetConfig(IdempotencyOptions options)
4754
{
4855
IdempotencyOptions = options;
4956
}
5057

58+
/// <summary>
59+
/// Set Persistence Store
60+
/// </summary>
61+
/// <param name="persistenceStore"></param>
5162
private void SetPersistenceStore(BasePersistenceStore persistenceStore)
5263
{
5364
PersistenceStore = persistenceStore;
@@ -79,10 +90,21 @@ public static void Configure(Action<IdempotencyBuilder> configurationAction)
7990
/// </summary>
8091
public class IdempotencyBuilder
8192
{
93+
/// <summary>
94+
/// Holds Idempotency options
95+
/// </summary>
8296
private IdempotencyOptions _options;
97+
/// <summary>
98+
/// Persistence Store
99+
/// </summary>
83100
private BasePersistenceStore _store;
84-
101+
/// <summary>
102+
/// Exposes Idempotency options
103+
/// </summary>
85104
internal IdempotencyOptions Options => _options;
105+
/// <summary>
106+
/// Exposes Persistence Store
107+
/// </summary>
86108
internal BasePersistenceStore Store => _store;
87109

88110
/// <summary>

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public class IdempotencyOptions
5858
/// </summary>
5959
public string HashFunction { get; }
6060

61+
/// <summary>
62+
/// Constructor of <see cref="IdempotencyOptions"/>.
63+
/// </summary>
64+
/// <param name="eventKeyJmesPath"></param>
65+
/// <param name="payloadValidationJmesPath"></param>
66+
/// <param name="throwOnNoIdempotencyKey"></param>
67+
/// <param name="useLocalCache"></param>
68+
/// <param name="localCacheMaxItems"></param>
69+
/// <param name="expirationInSeconds"></param>
70+
/// <param name="hashFunction"></param>
6171
internal IdempotencyOptions(
6272
string eventKeyJmesPath,
6373
string payloadValidationJmesPath,

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptionsBuilder.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@ namespace AWS.Lambda.Powertools.Idempotency;
77
/// </summary>
88
public class IdempotencyOptionsBuilder
99
{
10+
/// <summary>
11+
/// Default maximum number of items in the local cache.
12+
/// </summary>
1013
private readonly int _localCacheMaxItems = 256;
14+
/// <summary>
15+
/// Local cache enabled
16+
/// </summary>
1117
private bool _useLocalCache;
18+
/// <summary>
19+
/// Default expiration in seconds.
20+
/// </summary>
1221
private long _expirationInSeconds = 60 * 60; // 1 hour
22+
/// <summary>
23+
/// Event key JMESPath expression.
24+
/// </summary>
1325
private string _eventKeyJmesPath;
26+
/// <summary>
27+
/// Payload validation JMESPath expression.
28+
/// </summary>
1429
private string _payloadValidationJmesPath;
30+
/// <summary>
31+
/// Throw exception if no idempotency key is found.
32+
/// </summary>
1533
private bool _throwOnNoIdempotencyKey;
34+
/// <summary>
35+
/// Default Hash function
36+
/// </summary>
1637
private string _hashFunction = "MD5";
1738

1839
/// <summary>

libraries/src/AWS.Lambda.Powertools.Idempotency/Internal/IdempotencyAspectHandler.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,29 @@ namespace AWS.Lambda.Powertools.Idempotency.Internal;
2323

2424
internal class IdempotencyAspectHandler<T>
2525
{
26+
/// <summary>
27+
/// Max retries
28+
/// </summary>
2629
private const int MaxRetries = 2;
27-
30+
/// <summary>
31+
/// Delegate to execute the calling handler
32+
/// </summary>
2833
private readonly Func<Task<T>> _target;
34+
/// <summary>
35+
/// Request payload
36+
/// </summary>
2937
private readonly JsonDocument _data;
38+
/// <summary>
39+
/// Persistence store
40+
/// </summary>
3041
private readonly BasePersistenceStore _persistenceStore;
3142

43+
/// <summary>
44+
/// IdempotencyAspectHandler constructor
45+
/// </summary>
46+
/// <param name="target"></param>
47+
/// <param name="functionName"></param>
48+
/// <param name="payload"></param>
3249
public IdempotencyAspectHandler(
3350
Func<Task<T>> target,
3451
string functionName,
@@ -170,6 +187,11 @@ private Task<T> HandleForStatus(DataRecord record)
170187
}
171188
}
172189

190+
/// <summary>
191+
/// Get the function's response and save it to the persistence layer
192+
/// </summary>
193+
/// <returns>Result from Handler delegate</returns>
194+
/// <exception cref="IdempotencyPersistenceLayerException"></exception>
173195
private async Task<T> GetFunctionResponse()
174196
{
175197
T response;

libraries/src/AWS.Lambda.Powertools.Idempotency/Internal/LRUCache.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ internal sealed class LRUCache<TKey, TValue>
1818
/// </summary>
1919
private const int DefaultCapacity = 255;
2020

21+
/// <summary>
22+
/// Shared synchronization object
23+
/// </summary>
2124
private readonly object _lockObj = new();
25+
26+
/// <summary>
27+
/// Maximum number of elements to cache.
28+
/// </summary>
2229
private readonly int _capacity;
30+
31+
/// <summary>
32+
/// Dictionary to record the key and its data entry (O(1))
33+
/// </summary>
2334
private readonly Dictionary<TKey, Entry> _cacheMap;
35+
36+
/// <summary>
37+
/// Linked list that tracks LRU items (O(1))
38+
/// </summary>
2439
private readonly LinkedList<TKey> _cacheList;
2540

2641
/// <summary>
@@ -109,6 +124,10 @@ public void Set(TKey key, TValue value)
109124
}
110125
}
111126

127+
/// <summary>
128+
/// Deletes the specified key and value to the cache.
129+
/// </summary>
130+
/// <param name="key">The key of the element to remove.</param>
112131
public void Delete(TKey key)
113132
{
114133
lock (_lockObj)
@@ -118,6 +137,9 @@ public void Delete(TKey key)
118137
}
119138
}
120139

140+
/// <summary>
141+
/// Count of items in Cache
142+
/// </summary>
121143
public int Count
122144
{
123145
get
@@ -129,6 +151,10 @@ public int Count
129151
}
130152
}
131153

154+
/// <summary>
155+
/// Move to most recent spot (head) in Linked List
156+
/// </summary>
157+
/// <param name="node"></param>
132158
private void Touch(LinkedListNode<TKey> node)
133159
{
134160
lock (_lockObj)
@@ -141,6 +167,9 @@ private void Touch(LinkedListNode<TKey> node)
141167
}
142168
}
143169

170+
/// <summary>
171+
/// Linked List Element
172+
/// </summary>
144173
private struct Entry
145174
{
146175
public readonly LinkedListNode<TKey> Node;

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/BasePersistenceStore.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ namespace AWS.Lambda.Powertools.Idempotency.Persistence;
3333
/// </summary>
3434
public abstract class BasePersistenceStore : IPersistenceStore
3535
{
36+
/// <summary>
37+
/// Idempotency Options
38+
/// </summary>
3639
private IdempotencyOptions _idempotencyOptions = null!;
40+
41+
/// <summary>
42+
/// Function name
43+
/// </summary>
3744
private string _functionName;
3845
/// <summary>
3946
/// Boolean to indicate whether or not payload validation is enabled
4047
/// </summary>
4148
protected bool PayloadValidationEnabled;
49+
50+
/// <summary>
51+
/// LRUCache
52+
/// </summary>
4253
private LRUCache<string, DataRecord> _cache = null!;
4354

4455
/// <summary>
@@ -197,6 +208,12 @@ private void ValidatePayload(JsonDocument data, DataRecord dataRecord)
197208
}
198209
}
199210

211+
/// <summary>
212+
/// Retrieve data record from cache
213+
/// </summary>
214+
/// <param name="idempotencyKey">Idempotency key</param>
215+
/// <param name="now">DateTime Offset</param>
216+
/// <returns>DataRecord instance</returns>
200217
private DataRecord RetrieveFromCache(string idempotencyKey, DateTimeOffset now)
201218
{
202219
if (!_idempotencyOptions.UseLocalCache)
@@ -212,6 +229,11 @@ private DataRecord RetrieveFromCache(string idempotencyKey, DateTimeOffset now)
212229
}
213230
return null;
214231
}
232+
233+
/// <summary>
234+
/// Deletes item from cache
235+
/// </summary>
236+
/// <param name="idempotencyKey"></param>
215237
private void DeleteFromCache(string idempotencyKey)
216238
{
217239
if (!_idempotencyOptions.UseLocalCache)
@@ -282,6 +304,11 @@ private string GetHashedIdempotencyKey(JsonDocument data)
282304
return _functionName + "#" + hash;
283305
}
284306

307+
/// <summary>
308+
/// Check if the provided data is missing an idempotency key.
309+
/// </summary>
310+
/// <param name="data"></param>
311+
/// <returns>True if the Idempotency key is missing</returns>
285312
private static bool IsMissingIdemPotencyKey(JsonElement data)
286313
{
287314
return data.ValueKind == JsonValueKind.Null || data.ValueKind == JsonValueKind.Undefined
@@ -307,6 +334,12 @@ internal string GenerateHash(JsonElement data)
307334
return hash;
308335
}
309336

337+
/// <summary>
338+
/// Get a hash of the provided string using the specified hash algorithm
339+
/// </summary>
340+
/// <param name="hashAlgorithm"></param>
341+
/// <param name="input"></param>
342+
/// <returns>Hashed representation of the provided string</returns>
310343
private static string GetHash(HashAlgorithm hashAlgorithm, string input)
311344
{
312345
// Convert the input string to a byte array and compute the hash.

libraries/src/AWS.Lambda.Powertools.Idempotency/Persistence/DataRecord.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace AWS.Lambda.Powertools.Idempotency.Persistence;
2222
/// </summary>
2323
public class DataRecord
2424
{
25+
/// <summary>
26+
/// Status
27+
/// </summary>
2528
private readonly string _status;
2629

2730
/// <summary>

0 commit comments

Comments
 (0)