the implementation is modeled after src/common/shared_cache.hpp, with
following changes/improvements
* split the implementation into two parts:
- simple_lru.h: for the basic LRU cache. which tracks the least recently
used (LRU) cache using a list, and uses a map for lookup. in
future, we could use boost's multiple-index-container to replace
this combination.
- shared_lru.h: for the improved version of LRU cache, it also tries
to track the evcited but still alive objects using a customized
deleter of shared_ptr, and it keeps a map of weak_ptr pointing to
these objects. the customized deleter will remove the tracked
item in weak_ptr map once all shared_ptrs are destroyed.
* specialize LRUCache for ordered and non-ordered lookup. in existing
OSD, `SimpleLRU` is used for caching the encoded osdmaps, and we
don't use `lower_bound()`, `upper_bound()` or `get_next()` accessors
for accessing these maps, so no need to store them with `std::map`.
and in crimson-osd, it would be great if we can ditch `SimpleLRU`,
and reuse `LRUCache` directly if `SharedLRU` is overkill. so let's
prepare for this by specializing for the `unordered_map<>`.
* remove (not yet) unused methods from SharedLRU, like `purge()`,
dump_weak_refs()
* change some function signatures to resemble those in `std::map`,
for instance,
- change `lookup()` to `find()`
- change `lookup_or_create()` to `operator[]()`
* add comment to document `SharedLRU` class
* add test for SharedLRU
Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com> Signed-off-by: Kefu Chai <kchai@redhat.com>