I implemented a similar type of sound, which I called DynamicCache. It basically stores data in a list sorted by creation date. This can be easily changed to the last available date. The purpose of my cache is to cache database items that don't change very often. It caches items for 5 minutes, then deletes them so that they can be read again when they are available.
A cache search uses a map in which the key and iterator are stored in a list. The search uses the map to find the data in the list, and then, before returning the item, removes all old items from the end of the list. If the item is not in the cache, factory is called to provide data.
This approach should use a list to store data, since iterators on the map must always be valid if it used deque, iterators may be invalid after insertion. The list uses a structure to store data, a key, the time it was created (not the last access), and finally, if the data exists.
struct Record { KeyT key; DataT data; time_t createTime; bool exists; };
If your data is static and you want to keep the last access, then you can add a member of the structure access time and move the item to the top of the list each time it is available.
Here is my code, it looks a little more complicated, but this is mainly due to the template parameters and blocking reader entries.
#include "BWThread/BWReadersWriterLock.h"
iain
source share