Megatron
Megatron

Reputation: 2949

C++ memory cache data structure

I was wondering if there is an equivalent of the MemoryCache class from .net in C++? (http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx)

I'm loading audio files/images frequently in my program and I'd like to avoid reloading audio/video if I've recently used it by keeping it in a memory cache. I realize I could use a map or something similar, but I was wondering if there was a data structure that'd be better suited to this sort of thing? Additionalyl if I used a map, I'd have to continually check when to expire something from the map and remove it

Does boost include something like this? I have that available already.

Thanks in advance

Upvotes: 2

Views: 5525

Answers (3)

Piti Ongmongkolkul
Piti Ongmongkolkul

Reputation: 2120

I have that in my gist... just a light packaging of std::queue and std::unordered_map (queue is used for expiration). Queue based expiration may or may not suit your purpose though.

https://gist.github.com/2413834

Upvotes: 0

Chris K
Chris K

Reputation: 12359

Use boost to implement an LRU cache?

LRU implementation in production code

Upvotes: 2

Ben Voigt
Ben Voigt

Reputation: 283803

You mean like memcached or membase?

Upvotes: 1

Related Questions