-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache refactor, to have cache reset option accessible for unit tests …
…(build fix: clear cache after each test).
- Loading branch information
Showing
4 changed files
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* https://github.com/JaroslawWaliszko/ExpressiveAnnotations | ||
* Copyright (c) 2014 Jaroslaw Waliszko | ||
* Licensed MIT: http://opensource.org/licenses/MIT */ | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
|
||
namespace ExpressiveAnnotations.MvcUnobtrusive | ||
{ | ||
internal class MapCache | ||
{ | ||
private static readonly MapCache _instance = new MapCache(); | ||
private static readonly ConcurrentDictionary<string, CacheItem> _cache = new ConcurrentDictionary<string, CacheItem>(); | ||
|
||
private MapCache() | ||
{ | ||
} | ||
|
||
public static MapCache Instance | ||
{ | ||
get { return _instance; } | ||
} | ||
|
||
public CacheItem GetOrAdd(string key, Func<string, CacheItem> func) | ||
{ | ||
return _cache.GetOrAdd(key, func); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
_cache.Clear(); | ||
} | ||
} | ||
|
||
internal class CacheItem | ||
{ | ||
public IDictionary<string, string> FieldsMap { get; set; } | ||
public IDictionary<string, object> ConstsMap { get; set; } | ||
public IDictionary<string, string> ParsersMap { get; set; } | ||
public IDictionary<string, Guid> ErrFieldsMap { get; set; } | ||
public string FormattedErrorMessage { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters