Caching failure
|
Caching failure is a type of software bug, in which a program keeps results (caching) indicating a failure even after the failure has been corrected.
This occurs when out-of-date error indicator prevents a program from working correctly. An error occurs at some point, and a flag is set to indicate the error. The user takes the necessary steps to fix the error, but the error flag is not updated, so the program still does not work.
Only when failure is very expensive and the error condition arises automatically without user guidance should failure be cached. Caching failure creates a situation where the user is unable to isolate the cause of the failure: despite fixing everything he can think of, it still refuses to work! When failure is cached, the system should give a clear indication of what must be done to clear the flag so the system will try again, in addition to a description of the cause of the error.
An example: Consider a Web browser which attempts to load a page while the network is unavailable. The browser will receive an error code indicating the problem, and may display this error message to the user in place of the requested page. However, it is incorrect for the browser to place the error message in the page cache, as this would lead it to display the error again when the user tries to load the same page -- even after the network is back up. The error message must not be cached under the page's URL; until the browser is able to successfully load the page, whenever the user tries to load the page, the browser must make a new attempt.
Caching failure is an example of an anti-pattern.
This article is modified from text in the Perl Design Patterns Book.