diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-05-09 11:44:55 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-05-09 11:44:55 -0400 |
| commit | 039468f1cd9b2df2709e9bb3c2d6ed15086f587a (patch) | |
| tree | f711153f78db802489e82556b6ee59704993ac6d /MediaBrowser.Server.Implementations/Library/UserDataManager.cs | |
| parent | 99084edabeb1787f28496dffa55fbb260e34ae81 (diff) | |
| parent | e2e5a8ef3207e4a8e1172a5b3ffeacbdd063cd79 (diff) | |
Merge branch 'dev' of https://github.com/MediaBrowser/Emby into dev
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/UserDataManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/UserDataManager.cs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs index d3aad20f5..0fabbf54a 100644 --- a/MediaBrowser.Server.Implementations/Library/UserDataManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserDataManager.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Implementations.Library { public event EventHandler<UserDataSaveEventArgs> UserDataSaved; - private readonly ConcurrentDictionary<string, UserItemData> _userData = new ConcurrentDictionary<string, UserItemData>(); + private readonly Dictionary<string, UserItemData> _userData = new Dictionary<string, UserItemData>(StringComparer.OrdinalIgnoreCase); private readonly ILogger _logger; private readonly IServerConfigurationManager _config; @@ -66,8 +66,10 @@ namespace MediaBrowser.Server.Implementations.Library var newValue = userData; - // Once it succeeds, put it into the dictionary to make it available to everyone else - _userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; }); + lock (_userData) + { + _userData[GetCacheKey(userId, key)] = newValue; + } } catch (Exception ex) { @@ -154,13 +156,33 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentNullException("key"); } - return _userData.GetOrAdd(GetCacheKey(userId, key), keyName => GetUserDataFromRepository(userId, key)); + lock (_userData) + { + var cacheKey = GetCacheKey(userId, key); + UserItemData value; + if (_userData.TryGetValue(cacheKey, out value)) + { + return value; + } + + value = GetUserDataFromRepository(userId, key); + _userData[cacheKey] = value; + return value; + } } private UserItemData GetUserDataFromRepository(Guid userId, string key) { var data = Repository.GetUserData(userId, key); + if (data == null) + { + data = new UserItemData + { + UserId = userId, + Key = key + }; + } return data; } |
