goldsborough / lru-cache

:dizzy: A feature complete LRU cache implementation in C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Caches themselves should have a way to hold statistics, not just the memoization

goldsborough opened this issue · comments

It may make sense that the standalone caches also have helper classes to store statistics, i.e. not just the memoization stuff. Ideally this would not impact storage size if it is not wanted (i.e. don't pay for what you don't want/need)

One idea would be to have an additional class to store statistics (e.g. that knows what keys to monitor and can later give summaries), and be able to register it dynamically (decorator pattern)

This would be a perfect use case for std::optional. We can then just have the caches take boolean parameters (or, more nicely, enums) and accessors enable_statistics(<statistics object>)/statistics(), and create such a statistics object

One question is whether that statistics object should be supplied externally or created internally. Maybe they can be default constructible. A question is also if they should be shareable (i.e. should they just be pointers)