Skip to main content
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 ...
Peter Taylor's user avatar
  • 24.5k
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 ...
Peter Csala's user avatar
  • 10.8k
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 ...
kraskevich's user avatar
  • 5,660
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 ...
Jerry Coffin's user avatar
  • 34.1k
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 ...
Zeta's user avatar
  • 19.7k
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 ...
vnp's user avatar
  • 58.7k
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... ...
VisualMelon's user avatar
  • 7,591
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 ...
G. Sliepen's user avatar
  • 69.3k
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, ...
ChrisW's user avatar
  • 13.1k
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 ...
Kevmeister68's user avatar
5 votes

Thread-safe cache using a linked list

Thread safety std::malloc and std::free are thread-safe by themselves... But Freelist and <...
hoffmale's user avatar
  • 6,528
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 ...
AJNeufeld's user avatar
  • 35.3k
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 ...
200_success's user avatar
5 votes
Accepted

Decorator to cache a function result for some time

Rather than using *args you can supply a default positional only argument. ...
Peilonrayz's user avatar
  • 44.6k
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 ...
Toby Speight's user avatar
  • 88.3k
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, ...
h.j.k.'s user avatar
  • 19.4k
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 ...
t3chb0t's user avatar
  • 44.7k
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 ...
Joel's user avatar
  • 56
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 <...
hoffmale's user avatar
  • 6,528
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 ...
TheQult's user avatar
  • 268
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 ...
avismara's user avatar
  • 156
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 ...
janos's user avatar
  • 113k
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 ...
Toby Speight's user avatar
  • 88.3k
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 ...
user555045's user avatar
  • 12.4k
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 ...
JayDepp's user avatar
  • 541
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 ...
lauthu's user avatar
  • 141
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 ...
aghast's user avatar
  • 12.6k
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 ...
Flame239's user avatar
  • 489

Only top scored, non community-wiki answers of a minimum length are eligible