Merge remote-tracking branch 'remotes/origin/master' into release/1.2.9

This commit is contained in:
Robin 2016-05-24 13:13:48 +02:00
commit 0323705513
276 changed files with 5382 additions and 3666 deletions

View file

@ -31,10 +31,10 @@ namespace GreenshotPlugin.Core {
/// <typeparam name="TV">Type of value</typeparam>
public class Cache<TK, TV> {
private static readonly ILog LOG = LogManager.GetLogger(typeof(Cache<TK, TV>));
private IDictionary<TK, TV> internalCache = new Dictionary<TK, TV>();
private object lockObject = new object();
private int secondsToExpire = 10;
private CacheObjectExpired expiredCallback = null;
private readonly IDictionary<TK, TV> internalCache = new Dictionary<TK, TV>();
private readonly object lockObject = new object();
private readonly int secondsToExpire = 10;
private readonly CacheObjectExpired expiredCallback;
public delegate void CacheObjectExpired(TK key, TV cacheValue);
/// <summary>
@ -74,8 +74,11 @@ namespace GreenshotPlugin.Core {
get {
List<TV> elements = new List<TV>();
foreach (TV element in internalCache.Values) {
elements.Add(element);
lock (lockObject)
{
foreach (TV element in internalCache.Values) {
elements.Add(element);
}
}
foreach (TV element in elements) {
yield return element;
@ -105,8 +108,12 @@ namespace GreenshotPlugin.Core {
/// </summary>
/// <param name="key"></param>
/// <returns>true if the cache contains the key</returns>
public bool Contains(TK key) {
return internalCache.ContainsKey(key);
public bool Contains(TK key)
{
lock (lockObject)
{
return internalCache.ContainsKey(key);
}
}
/// <summary>
@ -168,7 +175,7 @@ namespace GreenshotPlugin.Core {
/// </summary>
private class CachedItem {
public event CacheObjectExpired Expired;
private int secondsToExpire;
private readonly int secondsToExpire;
private readonly Timer _timerEvent;
public CachedItem(TK key, TV item, int secondsToExpire) {