-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: Unique caches for simple_cache_middleware instances #2979
bugfix: Unique caches for simple_cache_middleware instances #2979
Conversation
29aed4f
to
9c32974
Compare
At present, if the ``simple_cache_middleware`` is imported and added to multiple instances of ``Web3``, these instances end up sharing a cache. This happens because the middleware is only constructed once and where we instantiate the cache if it is ``None`` is in the ``construct_simple_cache_middleware`` method. By moving the cache instantiation into the actual ``simple_cache_middleware``, we ensure that with each call to ``simple_cache_middleware``, a fresh cache will be instantiated if the ``cache`` was ``None`` to begin with.
9c32974
to
e0f1786
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking, just one suggestion for docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. An explanation + (maybe usage example?) in the docs would be sweet, but could be a separate PR too.
I updated the documentation for now and made sure it was up to date (it was poor to begin with and not up to date). I think I'm not understanding what makes this stand out from other middlewares and needs its own explanation other than the doc description. Maybe we create a ticket to better highlight that request and it becomes as separate PR? |
What was wrong?
closes #2977
How was it fixed?
For undefined
cache
arguments to*construct_simple_cache_middleware
methods, only create the cache at the middleware definition, not at the constructor method. This makes sure that a fresh cache is created each time the middleware is called (once for each instance). This was previously the case and I believe I broke it when we refactored the LRU cache out of this middleware.Tests added inspired by @cygnusv
Todo:
Cute Animal Picture