if (increasingCacheSize && pageReplacementCache.size() >= ERXSession.MAX_PAGE_REPLACEMENT_CACHE_SIZE * 2) {
boolean removedCacheEntry = cleanPageReplacementCacheIfNecessary(pageCacheKey); if (!removedCacheEntry && pageReplacementCache.size() >= ERXSession.MAX_PAGE_REPLACEMENT_CACHE_SIZE * 2) {
  public void savePage(WOComponent page) {    WOContext context = context();    WOResponse response = context.response();    if (response != null && (response.headerForKey(ERXSession.DONT_STORE_PAGE) != null || (response.userInfo() != null && response.userInfo().objectForKey(ERXSession.DONT_STORE_PAGE) != null))) {      String pageCacheKey = response.headerForKey(ERXSession.PAGE_REPLACEMENT_CACHE_LOOKUP_KEY);      if (pageCacheKey != null) {        String originalContextID = context.request().headerForKey(ERXSession.ORIGINAL_CONTEXT_ID_KEY);        pageCacheKey = originalContextID + "_" + pageCacheKey;        //System.out.println("ERXSession.savePage: " + pageCacheKey + " starting");        LinkedHashMap pageReplacementCache = (LinkedHashMap) objectForKey(ERXSession.PAGE_REPLACEMENT_CACHE_KEY);        if (pageReplacementCache == null) {          pageReplacementCache = new LinkedHashMap();          setObjectForKey(pageReplacementCache, ERXSession.PAGE_REPLACEMENT_CACHE_KEY);        }        boolean increasingCacheSize = true;        Iterator transactionRecordsEnum = pageReplacementCache.entrySet().iterator();        while (transactionRecordsEnum.hasNext()) {          Map.Entry pageRecordEntry = (Map.Entry) transactionRecordsEnum.next();          TransactionRecord tempPageRecord = (TransactionRecord) pageRecordEntry.getValue();          WOComponent tempPage = tempPageRecord.page();          WOContext tempContext = tempPageRecord.context();          // If the page has been GC'd, toss the transaction record ...          if (tempPage == null || tempContext == null) {            //System.out.println("ERXSession.savePage:   deleting GC'd page");            transactionRecordsEnum.remove();            increasingCacheSize = false;          }          else {            String transactionRecordKey = tempPageRecord.key();            if (pageCacheKey.equals(transactionRecordKey)) {              // If this is the "old page", then delete the entry ...              if (tempPageRecord.isOldPage()) {                //System.out.println("ERXSession.savePage: " + pageCacheKey + " removing old page " + tempPageRecord + " (context id = " + tempContext.contextID() + ")");                transactionRecordsEnum.remove();                increasingCacheSize = false;              }              // Otherwise, flag this entry as the old page ...              else {                //System.out.println("ERXSession.savePage:   " + pageCacheKey + " marking old page (contextid = " + tempContext.contextID() + ")");                tempPageRecord.setOldPage(true);              }            }          }        }        // Remove the oldest entry if we're about to add a new one and that would put us over the cache size ...        // We do a CACHE_SIZE*2 here because for every page, we have to potentially store its previous contextid to prevent        // race conditions, so there technically can be 2x cache size many pages in the cache.        if (increasingCacheSize && pageReplacementCache.size() >= ERXSession.MAX_PAGE_REPLACEMENT_CACHE_SIZE * 2) {          Iterator entryIterator = pageReplacementCache.entrySet().iterator();          Map.Entry oldestEntry = (Map.Entry) entryIterator.next();          entryIterator.remove();          //System.out.println("ERXSession.savePage: " + pageCacheKey + " removing oldest entry = " + ((TransactionRecord)oldestEntry.getValue()).key());        }        TransactionRecord pageRecord = new TransactionRecord(page, context, pageCacheKey);        pageReplacementCache.put(context.contextID(), pageRecord);        //System.out.println("ERXSession.savePage: " + pageCacheKey + " new context = " + context.contextID());      }    }    else {      super.savePage(page);    }  }