On Wed, 15 Feb 2023 at 09:37, Dino <d...@no.spam.ar> wrote: > > > Here's my problem today. I am using a dict() to implement a quick and > dirty in-memory cache. > > I am stopping adding elements when I am reaching 1000 elements (totally > arbitrary number), but I would like to have something slightly more > sophisticated to free up space for newer and potentially more relevant > entries. > > I am thinking of the Least Recently Used principle, but how to implement > that is not immediate. Before I embark on reinventing the wheel, is > there a tool, library or smart trick that will allow me to remove > elements with LRU logic? >
Check out functools.lru_cache :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list