All you need to do is call "setupCache" at the beginning of all your controllers that you want in the history, and then call "getHistory" with the index of the history item you wish to forward to (1 is the last page) to retrieve that pages URL. If you ever want a page to not cache, then pass it the query parameter "&noCache=T". I also don t cache "POST" requests, because they are form submission. Assuming neither of these conditions are true, we then add the current URL to the List object that holds our history on the session (mapped as HISTORY't;).
When adding to the cache, we limit the cache size to 3, because you do not want the session object per user to grow indefinitely, and I generally only care about the last page. However, you could easily increase this to 5 or 10 by replacing the constant value of "cacheMaxLength". Lastly, there is no reason to cache the same URL twice, as this usually happens when the user is refreshing the same page, so we ignore duplicate URLs.
So to summarize, all your view requests are cache by their URL, but only the current and last 2 pages, and you can prevent a page from being cached by passing the "noCache" parameter equal to "T". In order to retrieve the last page, simply call "getHistory(1)" for the URL.