开发者

Simple C/C++ in-process cache similar to memcached

开发者 https://www.devze.com 2023-04-12 04:56 出处:网络
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

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开发者_StackOverflow社区 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 hate to answer this way, but it would be fairly simple to implement yourself.

  1. Allocator. Use malloc and free. They do work, and they work well. This also makes it easier to interface with the rest of your program.

  2. 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.


I've had success using commoncache but the project doesn't appear to have any activity and issues raised (with patches) by my colleague are still unaddressed...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号