LibRingCache

2k Downloads

LibRingCache is an implementation of a cache that selectively lets the garbage collector collect old items but keeps the newest.

See documentation for usage information.

Why would you want to use this?

Currently you might just have a simple cache table with a _mode = "kv" metatable, but that isn't the best way because when the garbage collector runs, it will collect all entries no matter how old (or recent) they are. This cache implementation will ensure that you will keep your N most recent items in the cache.

Generally spoken, LibRingCache is useful to you if you want to keep X recent items, but still have to access them by an associative value (as opposed to just an incrementing number)

Because a cache that is always empty is useless.