You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
load_entity: disable_cache=True enables the cache when it was disabled #186
OSW.load_entity accepts LoadEntityParam.disable_cache, documented at src/osw/core.py:1159-1160 as "If true, disable the cache for the loading process". With disable_cache=True the cache is not disabled for the duration of the load. It is set to the opposite of the caller's starting state.
Code
src/osw/core.py:1222-1228:
# store original cache statecache_state=self.site.get_cache_enabled()
ifparam.disable_cache:
self.site.disable_cache()
ifnotcache_stateandparam.disable_cache:
# enable cache to speed up loadingself.site.enable_cache()
The second condition re-enables the cache exactly when the caller had it disabled. The two statements cancel each other.
Measured
Against a fake site that records the state when get_page is called, with disable_cache=True:
cache before the call
state during the load
state after the call
disabled
enabled
disabled
enabled
disabled
enabled
The state after the call is correct in both rows, so the restore works. The state during the load is inverted in the first row.
Consequence
A caller that already has the cache disabled and passes disable_cache=True to force a fresh read gets a cached read instead. That is the failure mode of #176: a get_page served from the cache can return a revision from before a write.
Open question
The comment "enable cache to speed up loading" suggests the second block was written on purpose. If that is the intended behaviour, then the field name and its docstring are wrong rather than the code, and the fix is to rename or document the field instead of removing the block. A maintainer decision is needed on which of the two is intended.
Related
#183 and #185 move the cache restore into a finally block. That PR deliberately leaves the behaviour described here unchanged.
Activity