Skip to content

Conversation

@hermitdave
Copy link
Contributor

Use ConcurrentDictionary instead of Dictionary in CacheBase
Use ConcurrentDictionary instead of OrderedDictionary in InMemoryStorage

@hermitdave
Copy link
Contributor Author

@IbraheemOsama as discussed before, this PR contains changes to ensure thread concurrency. I myself encountered item already added exception with CacheBase.

Add Created property to InMemoryStorageItem
Use Created property when removing additional items from InMemoryStorage
@hermitdave
Copy link
Contributor Author

@Odonno can you please review the update ?

{
_concurrentTasks.Add(fileName, request);
}
_concurrentTasks.TryAdd(fileName, request);
Copy link
Member

Choose a reason for hiding this comment

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

Try add without proper handling will sallow the operation, I mean what will happen if try add failed ? we should handle that or propagate the problem

Copy link
Member

Choose a reason for hiding this comment

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

of course TryRemove should be handled also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Use Index to set the cache request.
Use linq to query for expired items
_concurrentTasks.Remove(fileName);
}
}
_concurrentTasks.TryRemove(fileName, out request);
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to try again if the remove fails

}
InMemoryStorageItem<T> tempItem = null;

_inMemoryStorage.TryRemove(key, out tempItem);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool..so it cannot fail due to async reason :)

}

_inMemoryStorage.Remove(key);
_inMemoryStorage.TryRemove(id, out tempItem);
Copy link
Contributor

Choose a reason for hiding this comment

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

same:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would filename be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it can this bit is the least of our worries

Copy link
Contributor

Choose a reason for hiding this comment

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

I was mentioning the potential fail of TryRemove due to async op but after reading the link you sent, I'm ok this is fine!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes these concurrent types need careful looking into 🙂

Copy link
Contributor

@shenchauhan shenchauhan left a comment

Choose a reason for hiding this comment

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

A nice update


private Dictionary<string, ConcurrentRequest> _concurrentTasks = new Dictionary<string, ConcurrentRequest>();
private ConcurrentDictionary<string, ConcurrentRequest> _concurrentTasks = new ConcurrentDictionary<string, ConcurrentRequest>();
private object _concurrencyLock = new object();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this. It's no longer in use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot

{
lock (this)
foreach (var key in keys)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

key can still be null so need some code to check for it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot thought you meant in cache base. Muppet (me)


// clears expired items in in-memory cache
var keysToDelete = new List<object>();
DateTime expirationDate = DateTime.Now.Subtract(duration);
Copy link
Contributor

Choose a reason for hiding this comment

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

UTCNow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't want a fight with date time. Local time. Meh

@deltakosh deltakosh merged commit a39abc6 into dev Feb 13, 2017
@hermitdave hermitdave deleted the Cache-Concurrency branch February 13, 2017 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants