8000 feat: Added a generic LRUCache interface and a default implementation by mikechu-optimizely · Pull Request #311 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Added a generic LRUCache interface and a default implementation #311

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

Merged
merged 21 commits into from
Aug 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
671e159
Skeleton
mikechu-optimizely Aug 5, 2022
3d1ae15
LruCache initial implementation
mikechu-optimizely Aug 5, 2022
b987d9d
Add helper extensions
mikechu-optimizely Aug 5, 2022
295fdd2
WIP Fill unit tests
mikechu-optimizely Aug 5, 2022
50fd4e1
WIP corrections based on tests 2 more failing
mikechu-optimizely Aug 5, 2022
22acf8e
Remove SetTimeout, fix for non-passing test
mikechu-optimizely Aug 8, 2022
d2e3373
Add copyright notices
mikechu-optimizely Aug 8, 2022
d758efb
Remove InternalsVisibleTo for testing
mikechu-optimizely Aug 8, 2022
da33c99
Add new line at end of files via .editorconfig
mikechu-optimizely Aug 8, 2022
9fe246e
Readonly and remove excess methods/constructor
mikechu-optimizely Aug 8, 2022
33dc181
Code review corrections
mikechu-optimizely Aug 10, 2022
2f35de3
WIP code review changes
mikechu-optimizely Aug 10, 2022
24737fe
Possibly better solution to cast
mikechu-optimizely Aug 10, 2022
e042d99
Move readonlys into constructor
mikechu-optimizely Aug 10, 2022
6749182
Switch to using TimeSpan + refactors
mikechu-optimizely Aug 11, 2022
2bac003
A few more refactors
mikechu-optimizely Aug 11, 2022
03c9abf
Change underlying implementation of LRU
mikechu-optimizely Aug 12, 2022
209c3bd
Attempt to fulfill a default Timespan
mikechu-optimizely Aug 16, 2022
42a735d
Add logging; use 0s instead of descriptive consts
mikechu-optimizely Aug 16, 2022
722780c
Remove Tuple from LRU Cache
mikechu-optimizely Aug 16, 2022
ea2f32a
Remove System.ValueTuple NuGet package
mikechu-optimizely Aug 16, 2022
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
Prev Previous commit
Next Next commit
Move readonlys into constructor
  • Loading branch information
mikechu-optimizely committed Aug 10, 2022
commit e042d994d5301a4457c54eac469cbcd3074c3c5a
6 changes: 4 additions & 2 deletions OptimizelySDK/Odp/LruCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ public class LruCache<T> : ICache<T>
public const int DEFAULT_TIMEOUT_SECONDS = 600;

private readonly ILogger _logger;
private readonly object _mutex = new object();
private readonly object _mutex;
private readonly int _maxSize;
private readonly long _timeoutMilliseconds;
private readonly OrderedDictionary _orderedDictionary = new OrderedDictionary();
private readonly OrderedDictionary _orderedDictionary;

public LruCache(int maxSize = DEFAULT_MAX_SIZE,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, ILogger logger = null
)
{
_mutex = new object();
_maxSize = Math.Max(0, maxSize);
_timeoutMilliseconds = Math.Max(0, timeoutSeconds) * 1000L;
_logger = logger ?? new DefaultLogger();
_orderedDictionary = new OrderedDictionary();
}

public void Save(string key, T value)
Expand Down
0