java - Track visitors in play framework 2 application,caching and saving to DB -


what want accomplish sane way of storing list of pages visited during each anonymous user session on website. important sequence correct , 1 users navigation not mixed ones.

it similar c# question: "track visitor info on every request", proposed use logfile short-term storage. site host ~2k users/day think fine having cache in memory (atleast seems easier).

i cant seem figure out solution work stateless play framework since solution requires saving data(to db) when user has timed out , not active anymore. idea rely on storing each request in memory , call database if new request hasnt arrived in time (user timeout). how possible that?

is there other way think might better, perhaps storing requests users , making big write db instead of 1 each session?

edit:

i have taken easy way out, have been great salem mentioned cant figure out how save list memory. first plan use akka scheduler altered (timer reset , new post added) each time user gets new page dont know how in touch instance ion memory previous request if tell me grateful.

for have solved problem "bad way" requests database each page view. code below in case wanna bad:

in action:

        string uuid=session("uuid");         logger.info("old uuid:"+uuid);          string generatedid = usertracker.updatetracker(uuid,id.tostring()).tostring();          if(uuid==null || !generatedid.equals(uuid)){             logger.info("new uuid user:"+generatedid);             session("uuid", generatedid);         } 

usertracker class:

@entity public class usertracker extends model {  @id @sequencegenerator(name="ut_gen", sequencename="user_tracker_seq", allocationsize=1) @generatedvalue(strategy = generationtype.sequence, generator="ut_gen")  long session_id; string navigations;    public static long updatetracker(string session,string page){     usertracker ut=null;      try{     long sessionid=long.parselong(session);     ut = usertracker.find.byid(sessionid);         if(ut!=null)         {             ut.addpage(page);             ut.update();         } else {             throw new numberformatexception();         }     } catch (numberformatexception e){              ut = new usertracker(page);             ut.save();     }      return ut.session_id; }   private void addpage(string page) {     // todo auto-generated method stub     if(navigations!=null && !navigations.isempty())         navigations+=","+page;     else         navigations=page;   }    public usertracker(string page){     addpage(page);     save(); }  public static finder<long,usertracker> find =          new finder<long,usertracker>(long.class,usertracker.class);  } 


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -