Stale cached value returned after external file change in Memoized subroutine
26K reputation · 27 Mar 2024, 02:39 UTC
Goal: guarantee that a memoized subroutine returns up‑to‑date data when the underlying external resource (e.g., a file or database) changes, including after a process fork where the child should see its own environment.
Constraints: the Memoize module stores results keyed only by argument values and never expires entries automatically; after a fork the child process inherits the parent’s %Memoize::CACHE, so stale values persist until the cache is manually flushed. No standard hook exists to trigger invalidation on fork or on external events.
Uncertainty: the documentation notes an unresolved design decision about providing an optional callback for automatic cache invalidation after a fork, but no consensus on its interface or impact on threaded builds.
Should Memoize offer an optional flush‑on‑fork hook, and if so, what function signature would be appropriate? How would such a hook interact with existing Cache or LOCK options in threaded Perl builds? What fallback behavior should be used when the hook is not defined?