refactor: replace @web.memoize with @functools.cache#12057
Merged
cdrini merged 1 commit intointernetarchive:masterfrom Mar 17, 2026
Merged
Conversation
Fixes internetarchive#12017. Replaced parameterless @web.memoize instances with Python's built-in @functools.cache across 14 files. Explicitly avoided vendor/infogami files and functions with expiration/background parameters.
Contributor
Author
|
@RayBB when you have bandwidth, could you please take a look at this PR? Thanks! |
Collaborator
|
@cdrini is the lead so he'll have to look at this. Since there's a lot going on now it probably won't be merged soon. |
cdrini
approved these changes
Mar 17, 2026
Collaborator
cdrini
left a comment
There was a problem hiding this comment.
Lgtm! Tested and the site seems to be performing normally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12017
Technical
Replaced parameterless
@web.memoizeinstances with Python's built-in@functools.cacheacross 14 files. Explicitly excludedvendor/infogamifiles and the 3 instances withexpiry/backgroundparameters., following @cdrini's guidance:Design Decision:
@functools.cacheI intentionally usedimport functoolsand the fully qualified@functools.cachedecorator to avoid namespace collisions. Many modified files already containfrom openlibrary.core import cache, and usingfrom functools import cachewould have shadowed that module, leading to runtimeTypeError: 'module' object is not callableerrors.Excluded — require async-friendly background caching solution (tracked in #12017):
get_ol_dumpsinopenlibrary/plugins/upstream/data.py_get_recent_changesinopenlibrary/plugins/upstream/utils.py_get_recent_changes2inopenlibrary/plugins/upstream/utils.pyExcluded — vendored submodule:
vendor/infogamifiles require a separate PR againstinternetarchive/infogamiTesting
docker compose upand verify the application loads with no circular import or unhashable type errors on startup.Screenshot
N/A — no UI changes.
Stakeholders
@cdrini @RayBB