Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some comments to datacache #1347

Merged
merged 5 commits into from
Jan 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 TValue this[TKey key]
}
}

/// <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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we need to add an exception description about ArgumentException ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand, @Tommo-L.

Could you please add or explain more? I almost forgot the idea...aehauehae
That is why it is good to have these comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the Add method may throw ArgumentException exception, it will be better to add an exception comment 😂 , like the following format:

/// ....
/// <param name="value">Corresponding value to be added, in the case of sucess.</param>
/// <exception cref="ArgumentException">comments.....</exception>  <------
 public void Add(TKey key, TValue value)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks! Good idea.

{
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 DataCache<TKey, TValue> CreateSnapshot()
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