LRU cache design

后端 未结 11 2025
借酒劲吻你
借酒劲吻你 2020-11-27 09:26

Least Recently Used (LRU) Cache is to discard the least recently used items first How do you design and implement such a cache class? The design requirements are as follows:

11条回答
  •  野性不改
    2020-11-27 10:14

    I have a LRU implementation here. The interface follows std::map so it should not be that hard to use. Additionally you can provide a custom backup handler, that is used if data is invalidated in the cache.

    sweet::Cache, 48> c1;
    c1.insert("key1", std::vector());
    c1.insert("key2", std::vector());
    assert(c1.contains("key1"));
    

提交回复
热议问题