15
votes
Accepted
LeetCode: LRU cache implementation C#
The indentation is inconsistent: the test class has its {} indented the same as the class declaration, but the main class has them indented one level more.
It's ...
10
votes
Thread safe cache to sql call in c#
Naming
In your provided code sample, you are using inconsistent naming. I would suggest trying to pursue consistency to make maintenance easier. For C# you can find several guidelines what you can ...
8
votes
Accepted
LRU cache implementation in C++ using unordered_map and doubly linked list
Code simplification
You don't need to use a custom linked list here. std::list will do fine, too.
You can keep the pairs ...
8
votes
Accepted
Implementation of LRU cache
Namespace Usage
I'd put all of this into some namespace, so it won't accidentally collide with other usage of the names it defines.
I'd probably also work even a little harder to do something to hide ...
8
votes
Implementation of LRU cache
Header guards
Your code contains undefined behaviour since the underscores are reserved for the implementation:
17.6.4.3 Reserved names [reserved.names]
The C++ standard library reserves the ...
8
votes
Implementation of LRU cache
There is no reason for node to know the key.
The node constructor shall make a completely created node, that is prev and ...
8
votes
Accepted
Wrapping IMemoryCache with SemaphoreSlim
Sorry this is a bit of a ramble, but a few things jump out at me:
17?!?! I don't have to tell you about magic numbers! This should probably be configurable... ...
8
votes
Simple LRU cache implementations in C++20
This looks like a nice, straightforward implementation of a LRU cache, leveraging STL containers to do most of the heavy lifting (and the second version all of the heavy lifting). Still, there is some ...
7
votes
LeetCode: LRU cache implementation C#
This is a simple implementation but its performance wouldn't scale well for large numberOfCacheCells values.
In particular, ...
5
votes
Caches implementation in C++
I realise this is an old post, but one thing jumps out at me looking at the implementation:
How does your Get( ) method prevent the cached value being destroyed ...
5
votes
Thread-safe cache using a linked list
Thread safety
std::malloc and std::free are thread-safe by themselves... But Freelist and <...
5
votes
LRU Cache in constant time
Usual comment: add """docstrings""" to public methods at the very least.
Avoid double (and triple) lookups. Python has fast exception handling. Instead of ...
5
votes
LRU Cache in constant time
Outside of beginners' programming courses and interview quizzes, linked lists are rarely useful. Theoretically, they may be efficient, but in practice, the memory allocation and memory fragmentation ...
5
votes
Accepted
Decorator to cache a function result for some time
Rather than using *args you can supply a default positional only argument.
...
5
votes
Simple LRU cache implementations in C++20
Overview
I don't see any good reason to implement our own linked list. The version with std::list is shorter and clearer, and my guess is that we won't measure a ...
4
votes
Rest API for realtime statistics of last 60 seconds
Gathering statistics
The DoubleSummaryStatisticsClass class will be a perfect replacement for your bespoke Statistics class, ...
4
votes
CacheManager - Dependency injection
You are not doing dependency injection but using another pattern which is called service locator which isn't by the way so cool becasue classes using it depend on the ...
4
votes
Accepted
Property caching
You could potentially use incremental computation (think Excel cells that cache values).
Some details (in F#) here:
https://fsprojects.github.io/FSharp.Data.Adaptive/
The above is ported from the ...
4
votes
Accepted
Cache friendly string
Implementation
SmallString::c_str() does not return a C style string in some cases (e.g. if size() == BYTES), because the final <...
4
votes
Accepted
Memory cache implementation with a static class inside a normal class
The MemoryCache is thread safe, all those locks and semaphore are useless.
Also, the Memory Cache by itself makes some serializations so at every update you are deserializing the whole collection of ...
4
votes
Accepted
Custom caching class in Swift
Your Cache class cannot be lighter than it already is. The most you can do is, introduce generics to remove the redundant casting every time you are trying to fetch ...
4
votes
Accepted
Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)
Information hiding
If ProcessNode is only used by LRUCache,
then it's an implementation detail that's best hidden from other ...
4
votes
Accepted
LRU Cache in C++11
Headers
We're missing some headers. I'm guessing that your platform happens to include these as a side-effect of including <list> and ...
4
votes
Cache-optimized matrix multiplication algorithm in C
The block size shouldn't be 12 (more like 1 to 2 orders of magnitude bigger), but I don't know exactly what it should be and it's easier to try some values and see how they work out than trying to ...
4
votes
Accepted
Rust closure to be called on a cache miss
I like what you've done! I don't have too many comments about the content of it, since it looks good. However, you'll see below that I changed the field name value ...
4
votes
java Thread-safe LRUCache implementation
Advice 1
This implementation is not thread safe. For example, if two threads invoked getElement(key1) simultaneously, they may runs to ...
4
votes
Least Recently Used Cache Daily Coding Practice
Your code reads very much like you have written some Java and are trying to translate it to Python. You need to "drink the Kool-Aid" and start embracing idiomatic Python, instead.
First, start by ...
4
votes
Thread-safe LRU Cache Implementation in Java
I like the codestyle!
Code organization tips:
Its better to move DDLNode into LRU and make it static, because sole purpose of ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cache × 274c# × 76
java × 57
python × 32
c++ × 29
performance × 26
multithreading × 25
thread-safety × 25
javascript × 24
php × 21
concurrency × 16
algorithm × 14
.net × 11
c++11 × 10
object-oriented × 9
hash-map × 8
python-3.x × 7
generics × 7
redis × 7
c × 6
linked-list × 6
http × 6
memoization × 6
beginner × 5
array × 5