Skip to content

Commit

Permalink
Adding some comments to datacache (#1347)
Browse files Browse the repository at this point in the history
* Adding some comments to datacache

* Adding Exception comment tip of @Tommo-L

Co-authored-by: Shargon <shargon@gmail.com>
  • Loading branch information
vncoelho and shargon committed Jan 6, 2020
1 parent 225948b commit 6a91212
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/neo/IO/Caching/DataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class Trackable
}
}

/// <summary>
/// Try to Add a specific key, with associated value, to the current cached dictionary.
/// It will not read from internal state.
/// However, if previously cached into Dictionary, request may fail.
/// </summary>
/// <param name="key">Key to be possible added.
/// Key will not be added if value exists cached and the modification was not a Deleted one.
/// </param>
/// <param name="value">Corresponding value to be added, in the case of sucess.</param>
/// <exception cref="ArgumentException">If cached on dictionary, with any state rather than `Deleted`, an Exception will be raised.</exception>
public void Add(TKey key, TValue value)
{
lock (dictionary)
Expand All @@ -60,6 +70,9 @@ public void Add(TKey key, TValue value)

protected abstract void AddInternal(TKey key, TValue value);

/// <summary>
/// Update internals with all changes cached on Dictionary which are not None.
/// </summary>
public void Commit()
{
foreach (Trackable trackable in GetChangeSet())
Expand All @@ -82,6 +95,10 @@ public void Commit()
return new CloneCache<TKey, TValue>(this);
}

/// <summary>
/// Delete key from cached Dictionary or search in Internal.
/// </summary>
/// <param name="key">Key to be deleted.</param>
public void Delete(TKey key)
{
lock (dictionary)
Expand Down Expand Up @@ -186,6 +203,14 @@ public IEnumerable<Trackable> GetChangeSet()

protected abstract TValue GetInternal(TKey key);

/// <summary>
/// Try to Get a specific key from current cached dictionary.
/// Otherwise, tries to get from internal data with TryGetInternal.
/// </summary>
/// <param name="key">Key to be searched.</param>
/// <param name="factory">Function that may replace current object stored.
/// If object already exists the factory passed as parameter will not be used.
/// </param>
public TValue GetAndChange(TKey key, Func<TValue> factory = null)
{
lock (dictionary)
Expand Down

0 comments on commit 6a91212

Please sign in to comment.