package page.example;

import org.wikiwebserver.core.WareHouse;
import org.wikiwebserver.handler.http.interfaces.*;
import page.config.SiteTemplatedPage;


public class PersistentData extends SiteTemplatedPage implements HTTPResponder {
	
    public void generate() {
        
        setTitle("Persistent data example - WikiWebServer.org");

        append("<h1>Welcome Guest</h1>");
        
        Long last = (Long) getPageData().get("lastAccess");
        if (last != null) {
            String printable = WareHouse.formatStandardDate(last);
            append("<p>The last access to this page was " + printable + ".</p>");
        }
        getPageData().put("lastAccess", System.currentTimeMillis());
        
        long count = getPageData().incrementLongValue("accesses", 1);
        append("<p>This page has been accessed " + count + " times.</p>"); 
    }
    
    @Override
    public String getCacheKey() {
        return null;
    }
}
