I need a simple (LRU) cache which should run in-process. I found memcached, which looks great but there does not seem to be an easy way to host it in-process. I don’t need a distributed cache, just a simple key/value store and some kind of LRU behaviour and some nice allocator to limit fragmentation, as the entry size varies a lot (few bytes — few kilobytes.) There must be surely an existing implementation of such a thing? Should be C or C++.
I need a simple (LRU) cache which should run in-process. I found memcached, which
Share
I hate to answer this way, but it would be fairly simple to implement yourself.
Allocator. Use
mallocandfree. They do work, and they work well. This also makes it easier to interface with the rest of your program.Mutex -> hash table, tree, or trie. You can use a linked list to track LRU. Don’t try to do fancy lockless stuff.
Should weigh less than a couple hundred lines, knock it out in a good solid day.